代碼是做什麼你告訴它做的事,我想也許你不明白是什麼你告訴它要做。
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'
VS:
s = the address of the string "nice to meet you"
(s+1) = the address of the string "ice to meet you"
你*真正理解*這是什麼一樣'* s'?如果沒有,請參考你的書 - 通常指針很早就被引入了...... – Nim
如何在調試器中運行它? –
你的程序沒有什麼問題,它完全符合你的要求。你知道你在告訴它做什麼嗎? – Mike