Solved
variable gets undefined behaviour out of the loop body
Hi,
I am writing C++ program on Visual Basic first, once it is compiled I will port it into STM32 Cube IDE environment. I wrote a simple for loop. When I run this code, I get very strange value for z out of the loop that is 1971940899.
You can see the terminal output as below.
when z is equal to 10, the loop will be broken out
5
when z is equal to 10, the loop will be broken out
6
when z is equal to 10, the loop will be broken out
7
when z is equal to 10, the loop will be broken out
8
when z is equal to 10, the loop will be broken out
9
when z is equal to 10, the loop will be broken out
1971940899
Could you please help me resolve ?
Thanks.
for(int z=5;z<15;z++)
{
cout<<"when z is equal to 10, the loop will be broken out\n";
if(z==10)
{
break;
}
cout<<z<<endl;
}
cout<<z<<endl;
