gpt4 book ai didi

c - 赋值运算符如何作用于二维字符数组的元素?

转载 作者:行者123 更新时间:2023-11-30 21:06:02 24 4
gpt4 key购买 nike

对于下面的代码片段,我不明白如何为names[1][2] 因为它返回第 1 行中第 2 列的地址。我们如何分配 names[2][1]

它将第 2 行第 1 列的地址返回到 names[1][2]

我无法理解如何将一个列地址存储在另一个列地址中。

这句话的意义何在?

names[1][2]=names[2][1] ;   // what is it doing
int main() {
char names[3][20] = { "success", "gateway", "engineers" };
int i;
char *t;

t = names[1][2];
names[1][2] = names[2][1];
names[2][1] = t;

for (i = 0; i <= 2; i++)
printf("%s ", names[i]);
return 0;
}

最佳答案

"how can we assign names[2][1] which returns address of column 1 in Row 2 to names[1][2]"

names[2][1] 不返回地址,它给出第三个字符串中的第二个字符(因为零索引)。

name[2][1] 在本例中是字符 n

因此,names[1][2]=names[2][1] 基本上是将 names[1][2] 分配给 处的字符>名称[2][1]

关于c - 赋值运算符如何作用于二维字符数组的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51011113/

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