Home > Back-end >  Strange for loop
Strange for loop

Time:04-04

Bool threeConsecutiveOdds (vector & Arr) {
for (int i=0; i If (arr [I] & amp; 1 & amp; & Arr [I + 1] & amp; 1 & amp; & Arr [I + 2] & amp; 1)
return true;
}
return false;
}
Vector C={1};
ThreeConsecutiveOdds (c);

?
The size of an array of 1, 1-2-1, 0 is greater than 1, how still in circulation

CodePudding user response:

1-2=1
I=0
A false forever

CodePudding user response:

reference 1/f, the truth is more important than right or wrong response:
=1-2-1
I=0
A false forever

False is not into the loop

CodePudding user response:

Very simple reason, because the size of the vector is the return value type size_t
And size_t is usually typedef unsigned int
Then the expression of intermediate control loop before operation will be promoted to unsigned int
So is true, then into the loop

CodePudding user response:

That is been quietly into your - 1, 4294967295,

CodePudding user response:

Unsigned a=1;
If (a> 1)
Printf (" & gt;>> \n");
The else
Printf (" & lt; <<\n");

This is truth,

CodePudding user response:

The size () function returns a value is an unsigned integer, then arr. The size () - 2 is a positive number, so the for (int I=0; i for (int I=0; i definition and array: vector C={1}; , I tried an error,
  • Related