© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

1. What are the decision making statements?

Ans:

There are three ways for taking decisions in a program. First way is to use the if-else statement, second way is to use the conditional operators and third way is to use the switch statement.

Ex - 1:  What is the output?
void main()
{
            int i;
            char a[]="\0";
            if(printf("%s\n",a))
                        printf("Ok here \n");
            else
                        printf("Forget it\n");
}

Ans:
 Ok here

Explanation:

Printf will return how many characters does it print. Hence printing a null character returns 1 which makes the if statement true, thus "Ok here" is printed.

Ex - 2:  What is the output?
void main()
{
            while(1){
                        if(printf("%d",printf("%d")))
                                    break;
                        else
                                    continue;
            }
}

Ans:
Garbage values

Explanation:

The inner printf executes first to print some garbage value. The printf returns no of characters printed and this value also cannot be predicted. Still the outer printf  prints something and so returns a non-zero value. So it encounters the break statement and comes out of the while statement.


SLogix Student Projects
bottom