Hello,
#define A 1+5
int a = A/A;
NSLog(@"value a %d",a);
it shows me the result is 11
Please can you explain me how it works? I want to understand the steps that the compiler does to show this result. thank you in advance.
Hello,
#define A 1+5
int a = A/A;
NSLog(@"value a %d",a);
it shows me the result is 11
Please can you explain me how it works? I want to understand the steps that the compiler does to show this result. thank you in advance.
int a = A/A
is expanded into int a = 1+5/1+5, i.e. 1 + 5 + 5 which is 11
maybe you'd want to make it #define A (1+5)
Macros are not functions. They don't calculate values and insert them into the code. A macro will be simply expanded as it is written.
And btw this is not compiler who expands macros, it is the preprocessor