What did you expect it to print?
Originally Posted by Ferris
I suggest that you compile and run this program:
I expect the output to be:
const char *text = "hello world!";
puts(text + 6);
The reason is that puts(text + 6) prints the substring starting from the character at index 6, i.e., the substring "world!". &text yields the same address as text + 6, hence puts(&text) prints the same substring.
What you did with printf is to use the string (or substring starting from index 1) as a format string. By right, you should have used:
But if you really want to print a single character, then write:
All the confusion that you have right now is due to the fact that whenever you claimed that you printed a single character, you didn't. You printed a string, or a substring thereof, or simply attempted to print a character as a string.