Original Post
🔒 Locked
printf problem
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.
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.
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.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement