When i compile the exact code in the course it doesnt work as mr mosh code

in the image you can see my code, it is suppose to cout the numbers in the array, in course 2 section 3 (determining the size of arrays) mr mosh types this exact code and gets the number of arrays and the loop stops, but when i wrote the exact same thing after arrays the loop continues and still prints random numbers so im really confused cause i know i wrote the same exact code but why his loop stops after counting the arrays but mine doesnt

and this is the code mr mosh wrote in the course:

#include

using namespace std;

int main(){

int numbers[] = {10, 20,30, 40, 50};
 for (int i = 0; 1 < size(numbers); i++)
     cout << numbers[i] << endl;


return 0;

}

You made a typo. Your loop condition is 1 < size(numbers) and since 1 is always smaller than the size of your array your loop will not end.

Replace the 1 in your condition by the loop variable i and it will work as expected.

2 Likes