I have this code
int main()
{
int arr[]={1,2,3,4,5,6,8,10,12,14};
int n=sizeof(arr)/sizeof(arr[0]);
int array[n];
int x=n;
while(x>0){
arr[x]=0;
x--;
}
return 0;
}
Basically I am getting error
** stack smashing detected ***: terminated
Aborted (core dumped)
when debugging in gdb I found when x
reaches value 2 in while
loop then it does not decrease and value stays at 2 means there is no outcome of statement x--;
in the while loop. why is this but when I do code while loop like this
while(x-->0){
arr[x]=0;
}
error goes away. What's happening there and why is not happening anymore
int main()
{
int arr[]={1,2,3,4,5,6,8,10,12,14};
int n=sizeof(arr)/sizeof(arr[0]);
int array[n];
int x=n;
while(x>0){
arr[x]=0;
x--;
}
return 0;
}