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/