What is the output of the below code?
#include <stdio.h>
#define website_pages(n) printf ("pagecount" #n " = %d", pagecount##n)
int main()
{
int pagecount_1 = 5;
website_pages(_1);
return 0;
}
-------------------------------------------------------------------------------
The above code tests below scenarios:
1. Stringizing Operator
2. Token-Pasting Operator
-------------------------------------------------------------------------------
# is a Stringizing operator and ## is a token-pasting operator in C language
Information regarding the stringizing operator and token-pasting operator is included in the below link:
Website_pages(_1) invokes a Macro, the Macro calls for printf statement
printf has pagecount initially after which #n is used and this stringizing operator converts _1 into string, so, now it is pagecount_1.
This displays 5 pagecount and n are combined using token-pasting operator ##
So, the output shall be pagecount_1 = 5
0 Comments