我不明白第5行中的“单词”一词是如何印刷的,有人可以向我解释吗?
#include <stdio.h>
int main(void) {
char str[50] = "hello\0 worl\bd";
printf("\n %s ",str);
printf("%s \n",str+str[4]-*str);
return 0;
}
因此,逐步:
“ str”指向您的字符串"hello\0 worl\bd"
,它实际上是"hello\0 word"
(因为\ b删除了前一个字符)
* str =是char指针的“内容”,表示字符串的第一个字符,即“ h”
str [4] =是str的第(4 + 1)个字符,即'o'
str [4]-* str ='o'-'h'
= 7 (但是为什么是7?'h'的ASCII字符值为104,'o'的值为111)] >
str + 7 =
因此,您基本上是在打印初始字符串的index:7开始的字符串。
因此:'word'
;)
首先是以下字符串: