In your loop, the condition i < size checked before i is increased. But, i increases before entering the body of the cycle, and not after it, therefore, in this case, you can access b[5] , since i will increase after checking i < size by i=4 . You do not want this, as this causes the program to behave undefined.
If you try to access an element in an array that does not exist, for example. array[size] , you get access to the next place in memory right after the array. In this case, you are lucky, but if this means that you are accessing a part of memory where your program is not allowed to do this, you will get a segmentation fault .
source share