Read more about the C preprocessor, notably stringification
So A(i)
is expanded into "i"
literal string (and A(strange !?)
would be expanded in "strange !?"
, assuming that strange
is not some #define
-d preprocessor macro). Hence s[0]
is 'i'
, (s[0] == 'i')
is true, represented as 1, so the output is -1 ...
You should have compiled your code with all warnings and debug information (gcc -Wall -Wextra -g
). Then run in a debugger (gdb
) your program step by step.
Notice also that int i = -i;
is (as commented by Cool Guy) undefined behavior; you really should be afraid of UB since it can be horrible (even if on my x86_64/Linux machine -with my usual compiler-, in this particular int i= -i;
case, it probably won't do a lot of harm, just a tiny bit).
You can also watch the preprocessed form, obtained using gcc -Wall -C -E
, in some editor or pager.
BTW your code sample is lacking #include <stdio.h>
PS. I recommend you to install Linux on your laptop and learn to use it (and its compiler) on the command line. Study also existing free software code, you could find good examples of stringification with the C preprocessor.