What would be the output of this program & Why#include#define one two#define two oneint main(){ int one=1,two=2; printf("%d%d",one,two); return 0;}

Questions by himanshujoshi

Showing Answers 1 - 6 of 6 Answers

baseersd

  • Jul 19th, 2007
 

This is the original code....

#include
#define one two
#define two one
int main()
{
//int one=1,two=2;
/*The above statement can be written as the following two statements for a better understanding */
int one=1;
int two=2;
printf("%d%d",one,two);
return 0;
}

When the code is preprocessed, then it changes one --> two and two-->one.

Hence the code after preprocessing changes to :
#include
#define one two
#define two one
int main()
{
int two=1;
int one=2;
printf("%d%d",two,one);
return 0;
}

Hence during the execution, first it prints the value pointed by variable two i.e 1 and then prints the value pointed by variable one i.e 2.

Hence the result is
12

Regards,
Syed Baseer Ahmed
baseersd @ gmail . com

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions