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

C and C++ Interview Questions

13. What is the Associativity of the increment and decrement operator?

Ans:
Right to left.

Ex - 1: What is the output?

main()
{
printf("%d", out);
}

int out=100;
Ans:
Compiler error: undefined symbol out in function main.

Explanation:
The rule is that a variable is available for use from the point of declaration. Even though a is a global variable, it is not available for main. Hence an error.

Ex - 2: What is the output?

main()
{
int i=-1;
+i;
printf("i = %d, +i = %d \n",i,+i);
}

Ans:
i = -1, +i = -1

Explanation:
Unary + is the only dummy operator in C. Where-ever it comes you can just ignore it just because it has no effect in the expressions (hence the name dummy operator).

Ex - 3: What is the output?

main()
{
int k=1;
printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");
}

Ans:
1==1 is TRUE

Explanation:
When two strings are placed together (or separated by white-space) they are concatenated (this is called as "stringization" operation). So the string is as if it is given as "%d==1 is %s". The conditional operator( ?: ) evaluates to "TRUE".


SLogix Student Projects
bottom