Sign in to follow this  
TEUTON

printf problem

Recommended Posts

TEUTON    100
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.

Share this post


Link to post
Share on other sites
Kambiz    758
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.

Share this post


Link to post
Share on other sites
jonahrowley    300
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this