output:dCode:#include<stdio.h>
int main()
{
short int a=5;
printf("%d"+1,a);
return 0;
}
Why is the output so?
Printable View
output:dCode:#include<stdio.h>
int main()
{
short int a=5;
printf("%d"+1,a);
return 0;
}
Why is the output so?
Why did you try this in the first place? I mean, I can tell you why, but it is a weird question to begin with.
Indeed, before I'll explain why it is "d", what were you hoping or thinking the output might be?
Need to know how the compiler works..why is it so?
I do not think randomly trying out snippets of C code will tell you how your compiler works. To learn how your compiler works, you should study compiler design. To learn how to program in C, you should work through some book/tutorial that provides a more structured approach to your learning of C.Quote:
Originally Posted by ranjit89
So nobody will answer it?
OK got it..don't bother:redface:
Okay, now *I* am curious. Despite the senslessness and given the fact that this kind of knowledge won't get me anywhere, would somebody explain the output anyway? :)
When the string literal "%d" is used as an argument to printf, it becomes a pointer to the address of the string. So when +1 is added to it, the pointer adress is incremented by one and points to "d" instead.