printf problem

Started by
3 comments, last by jonahrowley 18 years ago
What does this statement means...I have never seen such a way of using printf and it's even working fine in VC6.0.

   printf("%d"+2,123);

if I enter 6 instead of 2 I start getting ftbuf.c what is this? For larger numbers I don't get any output. I have no idea what is going around.
Advertisement
Try this:
printf("%s","abcdefg"+2);
you will get:
"cdefg"

so "%d"+2 means "" and printf("%d"+2,123) is equal to printf("",123) and the output will be nothing!

"blah blah blah..." is a pointer to the string (a const char* I think) so "blah blah blah..."+n is a pointer to the n-th character of the string.
Well you learn something every day don't you.

Dave
Quote:Original post by Dave
Well you learn something every day don't you.

Dave


Yes...that's right.
Character literals all get put into the same section. You can end up with pieces of an entierly different string, something from another section entirely (hate to see what happens when you try to print a jump table as a string), or if you're really unlucky, hit an address where there is no page mapped and pagefault.

This topic is closed to new replies.

Advertisement