#include <stdio.h>
int main()
{
printf("%c code\n", 'C');
printf("%d", "");
return 0;
}
#include <stdio.h>
int main()
{
printf("%d", 3); /* result 3 */
printf("%d", '3'); /* result 51, because 3 is char (from ASCII table) */
printf("%d", ""); /
return 0;
}
I'm a beginner at C. I read "C Programming Absolute beginner's Guide" Thurd Edition by Greg Pery and Dean Miller. There are examples of %c %d and %f . I've started experiment with them and noticed thing that i can't explain how it was made. So i tried these examples with %d and understood how first two work. For last one i have ideas how computer read this but I ain't sure how all 0s and 1s combine together. If you have explanation of that, I will glad to response you back)))
""is an empty string, not a character - i.e., it's a pointer with some fancy syntax sugar around it. Since you don't control where this string is allocated, it's allocated to an arbitrary location in the memory, and when using%dto print it, you get the offset from the beginning of the segment that contains it.Note that on multiple executions of the same program the first two
printfstatements will always print the same values (3 and 51, as you noted), but the third one may print a different number every time.