I have one doubt in the following snippet. Actually I am initializing all the array index to zero in following code, but this for loop is going infinitely. I found reason that we are trying to access the 26th index of array, so that value gets initialized to zero again since there is 0 to 25 index. So the for loop is going infinitely. Explain if any one the actual reason behind this stuff.
int array[26];
int i;
for (i = 0; i <= 26; i++)
array[i]= 0;
You have to use
i < 26; otherwise you exceed the array bounds.Due to the layout of the stack on most systems
array[26]will point to the memory used foriwhich results in the loop starting again since you loop body is setting i to 0 instead of an appropriate array element.Note that you can simply use
int array[36] = { 0 };to create the array with all elements being set to 0.