gpt4 book ai didi

c - 当我在c中添加带有unsigned long的字符数组时会发生什么?

转载 作者:行者123 更新时间:2023-11-30 20:57:26 25 4
gpt4 key购买 nike

#include <stdio.h>
#include<string.h>
void double_string(char ary[])
{
char *start = ary;
// dont exactly know what is happening here nothing is getting printed when consoled
char *end = ary + strlen(ary);
char *org = end;

while(start<org)
{
*end = *start;
start++;
end++;
}
*end = '\0';
}

int main(void) {
char word[255] = {"TACsasasa"};
double_string(word);
printf("%s",word);
return 0;
}

我无法理解字符数组“*end”中存储的内容,我尝试打印它,但没有打印任何输出。

最佳答案

char *end = ary + strlen(ary);

这行代码获取内存中 char 数组的起始地址,添加 strlen() 返回的数组内的字节数,并将指针移动到末尾。数组的末尾是空终止符。打印时不会显示任何内容,因为它将其视为空字符串。

关于c - 当我在c中添加带有unsigned long的字符数组时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59379817/

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