#include<stdio.h>
int main()
{
char s[]="chomsky the great";
printf("try0 %s\n",s+s[3]-s[9]);
printf("try1 %s\n",s+s[3]-s[1]);
return 0;
}
gcc 编译器中的 o/p 是
try0 ky the great try1 ky the great
我无法跟踪程序在这里实际做了什么,或者编译器是如何工作的。
最佳答案
s+s[3]-s[9] = s + *(s+3) - *(s+9) = s + 'm'- 'h' = s + 109 - 104 = s + 5 = s[5]
所以 printf 从 s[5] 开始打印
printf 打印的例子:
printf("%s",s) = chomsky the great
printf("%s",s[0]) = chomsky the great
printf("%s",s[2]) = omsky the great
printf("%s",s[5]) = ky the great
关于有人可以向我解释给定代码中发生了什么吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15693844/