Declarations and Initializations

Q1:
In the following program how long will the for loop get executed?
#include<stdio.h>
int main()
{
    int i=5;
    for(;scanf('%s', &i); printf('%d\n', i));
    return 0;
}

A
The for loop would not get executed at all

B
The for loop would get executed only once

C
The for loop would get executed 5 times

D
The for loop would get executed infinite times

ANS:A -

The for loop would not get executed at all

During the for loop execution scanf() ask input and then printf() prints that given input. This process will be continued repeatedly because, scanf() returns the number of input given, the condition is always true(user gives a input means it reurns '1'). Hence this for loop would get executed infinite times.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.