gpt4 book ai didi

有人可以向我解释给定代码中发生了什么吗?

转载 作者:太空狗 更新时间:2023-10-29 15:52:45 26 4
gpt4 key购买 nike

   #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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com