What will the following code print?
#include <iostream>

int main(int i, char * argv[])
{
   while(i = 0, i < 10, i++)
   {
      std::cout << i;
   }
}
Explanation
The while loop condition can be represented as three sequential operations:
i = 0;
i < 10;
i++;
The result of the last operation will be equal to i before the increment, i.e. zero or false, so the loop will not be executed at all.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
C++ quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes