Control Instructions

Q1:
What will be the output of the program, if a short int is 2 bytes wide?
#include<stdio.h>
int main()
{
    short int i = 0;
    for(i<=5 && i>=-1; ++i; i>0)
        printf('%u,', i);
    return 0;
}

A 1 ... 65535

B Expression syntax error

C No output

D 0, 1, 2, 3, 4, 5

ANS:A - 1 ... 65535

for(i<=5 && i>=-1; ++i; i>0) so expression i<=5 && i>=-1 initializes for loop. expression ++i is the loop condition. expression i>0 is the increment expression. In for( i <= 5 && i >= -1; ++i; i>0) expression i<=5 && i>=-1 evaluates to one. Loop condition always get evaluated to true. Also at this point it increases i by one. An increment_expression i>0 has no effect on value of i.so for loop get executed till the limit of integer (ie. 65535)



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.