Your code is wrong. When you compile it with a recent GCC compiler enabling warnings with
gcc -Wall -Wextra u.c
you get
u.c: In function 'main':
u.c:5:20: warning: multi-character character constant [-Wmultichar]
printf("%c\n", 'abcd');
^
u.c:6:20: warning: multi-character character constant [-Wmultichar]
printf("%p\n", 'abcd');
^
u.c:6:5: warning: format '%p' expects argument of type 'void *', but argument 2 has type 'int' [-Wformat=]
printf("%p\n", 'abcd');
^
Technically, you are in the awful undefined behavior case (and unspecified behavior for the multi-character constants), and anything could happen with a standard compliant implementation.
I never saw any useful case for multi-character constants like 'abcd'
. I believe they are useless and mostly are an historical artefact.
To explain what really happens, it is implementation specific (depends upon the compiler, the processor, the optimization flags, the ABI, the runtime environment, ....) and you need to dive into gory details (first look at the generated assembler code with gcc -fverbose-asm -S
) and into your libc particular printf
implementation.
As a rule of thumb, you should improve your code to get rid of every warnings your compiler is able to give you (your compiler is helpful in warning you). They are few subtle exceptions (but then you should comment your code about them).