output:dCode:#include<stdio.h> int main() { short int a=5; printf("%d"+1,a); return 0; }
Why is the output so?
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Indeed, before I'll explain why it is "d", what were you hoping or thinking the output might be?
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
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.Originally Posted by ranjit89
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
So nobody will answer it?
OK got it..don't bother
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.