gpt4 book ai didi

c - 如果我不说 int i=0 就会出现段错误

转载 作者:太空宇宙 更新时间:2023-11-04 01:03:02 26 4
gpt4 key购买 nike

void removeVowels(char* array){
int i,j,v;
i=0;

char vowel[]={'a','e','i','o','u'};
while(array[i]!='\0')
{
for(v=0;v<5;v++)
{
if (array[i]==vowel[v])
{
j=i;
while(array[j]!='\0')
{
array[j]=array[j+1];
j++;
}
i--;
break;
}
}
i++;
}


}

在函数 removeVowels() 中,如果我不包含 i=0;只说 int i; 为什么会出现段错误?不是自动0吗?

完整代码 here

最佳答案

Isn't it automatically 0?

不,不是。它 i 有自动存储,所以它的默认初始化让它未初始化,持有一个不确定的值。在初始化之前读取它是未定义的行为

关于c - 如果我不说 int i=0 就会出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30987630/

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