代码正在做你告诉它做的事情,我想你可能不明白你告诉它做什么。
char *s = "nice to meet you!";
// s is a pointer to a character
// s* is the character that "s" points to
您已s
指向字符“n”。s
也恰好指向以 NULL 结尾的字符串文字中的第一个字符。
printf("Original character: %c\n",*s); //Note the %c, we're looking at a character
output-> Original character: n
printf("Original string: %s\n",s); //Note the %s, and we're feeding the printf a pointer now
output-> Original string: nice to meet you!
当涉及到偏移量时:
*s = the character s is pointing at, 'n'
*(s+1) = the next character s is pointing at, 'i'
与:
s = the address of the string "nice to meet you"
(s+1) = the address of the string "ice to meet you"