gpt4 book ai didi

c - 像 arr ['' hi there"] 这样的表达意味着什么?

转载 作者:太空狗 更新时间:2023-10-29 16:33:07 26 4
gpt4 key购买 nike

如果 a=3 和 b=5 这意味着什么?

printf(&a["Ya!Hello! how is this? %s\n"], &b["junk/super"]);

我知道arr[4]表示 *(arr+4)所以我需要知道像 "hi there" 这样的表达式是什么意思暗示?

编辑 - 问题可能更清楚:

当字符串用作数组下标时,它传达什么值?

为什么上面的输出是Hello! how is this? super

最佳答案

这意味着,printf 等价于此:

printf("Hello! how is this? %s\n", "super");

将打印:

Hello! how is this? super

在线演示:http://ideone.com/PVzUP

解释:

当我们写 char s[]="nawaz; 然后 s[2] 表示字符串 s 中的第 3 个字符。我们可以通过写 "nawaz"[2] 来表达这一点,这也意味着字符串 "nawaz" 中的第 3 个字符。我们也可以写成 2["nawaz"] 这也意味着字符串中的第 3 个字符。在您的代码中,printf 使用最后一种形式,即 2["nawaz"] 的形式。不过,这很不寻常。

所以 a["Ya!Hello! how is this? %s\n"] 表示字符串中的第 4 个字符(因为 a 的值为 3) ,如果您在 a 前面添加 &,则 &a["Ya!Hello! how is this? %s\n"] 返回字符串中第 4 个字符的 地址,这意味着,在 printf 中它等效于:

Hello! how is this? %s\n

我希望你能自己理解其余部分。

关于c - 像 arr ['' hi there"] 这样的表达意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6767350/

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