Re: C- Tricky Question & answers With explanation 1)
#ifdef something
int some=0;
#endif
main()
{
int thing = 0;
printf("%d %d\n", some ,thing);
} Answer:
Compiler error : undefined symbol some Explanation:
This is a very simple example for conditional compilation. The name something is not already known to the compiler making the declaration
int some = 0;
effectively removed from the source code.
2)
#if something == 0
int some=0;
#endif
main()
{
int thing = 0;
printf("%d %d\n", some ,thing);
} Answer:
0 0 Explanation:
This code is to show that preprocessor expressions are not the same as the ordinary expressions. If a name is not known the preprocessor treats it to be equal to zero.
3)
void main()
{
if(~0 == (unsigned int)-1)
printf(“You can answer this if you know how values are represented in memory”);
} Answer:
You can answer this if you know how values are represented in memory Explanation
~ (tilde operator or bit-wise negation operator) operates on 0 to produce all ones to fill the space for an integer. –1 is represented in unsigned value as all 1’s and so both are equal.
__________________
J.Vijayanand |