the program never executes ‘0’ in my string array of chars

Your program first creates an array:

char const ord[MAX] = { "Hello" };

The array is represented in memory as 6 characters: 'H', 'e', 'l', 'l', 'o', '\0'

The indexes of these characters are 0, 1, 2, 3, 4, 5.

When you start your for loop, you need to start at index MAX - 1, index 5, because index 6 is not part of the array.

Another thing is that size_t is an unsigned type, meaning it can not go below 0. Because of this, i >= 0 will always be true so the loop will never end. You can use i != -1 because unsigned integer underflow is defined.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top