376 views
0 votes
0 votes
#include<stdio.h>
#define A -B
#define B -C
#define C 5

int main()
{
  printf("The value of A is %dn", A); 
  return 0;
} 

what is the output?????

1 Answer

0 votes
0 votes

Short answer The value of A is 5n

Possible Explanation:
#define macro would replace the respective constant with A, B and C with provided expression/value. So for our problem let's evaluate. (keep in mind, while replacing #define macro don't add/remove space or anything, put as it is)

So printf statement would become:
printf (" %d ", - -5 ) | See extra space it would be there while we were expending B.

Now you can see resultant value would be 5. 

Also, you can see macro processed input to compiler using $ gcc file.c -E.

Let me know your thoughts or if something I missed.

edited by