K
K
kykyryky2015-11-11 20:02:54
C++ / C#
kykyryky, 2015-11-11 20:02:54

How does the program work?

#define A abc 
#define B(arg) #arg 
#define C(arg) B(arg) 
#include "stdio.h"
int main() 
{ 
printf("%s\n",B(A));//"А"
printf("%s\n",C(A));//"abc"
}

Conclusion:
And
abc

Why does it work like that? Why does it output not A and A, or not abc and abc?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Tsilyurik, 2015-11-11
@kykyryky

It's elementary from C syntax : in macros #arg - don't resolve arg value.
In the second case, C(A) resolves the argument A even before calling B(A).
PS Just write the tags correctly - this is C, not C ++!

S
Sergey, 2015-11-11
Protko @Fesor

https://msdn.microsoft.com/en-us/library/7e3a913x.aspx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question