In a file xyz.c
int p=2; //global
#define sum(p,i) p+i
int main()
{
printf("%d", sum(5,6));
}
output here would be 11 (and not 8); why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Output is definitely
11.Because
pis not considered as a variable inside the macro, it’s just like a token which has a invocation value; e.g.(5,6). The scope of the token is limited to macro scope.Suppose you change the macro as below, then the output will be 8: