How many times will GeeksQuiz be printed in the below program?
#include
using namespace std;
int main()
{
int i = 1024;
for (; i; i >>= 1)
cout << \"GeeksQuiz \";
return 0;
}
[/sourcecode]
(A) 10
(B) 11
(C) infinite times
(D) The program will show compile-time error
Answer: (B)
Explanation: In for loop, mentioning expression is optional. >>= is a composite operator. It shifts the binary representation of the value by 1 to the right and assigns the resulting value to the same variable. The for loop is executed until value of variable i doesn’t drop to 0.
Quiz of this Question
Share your thoughts in the comments
Please Login to comment...