100% found this document useful (1 vote)
195 views

Control Flow Statements: Printf

The document discusses 16 multiple choice questions related to control flow statements in C programming. Some key questions cover if-else conditional statements, switch statements, while and for loops, break and continue keywords, goto statements. The correct answers are provided for each question.

Uploaded by

mayande rohini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
195 views

Control Flow Statements: Printf

The document discusses 16 multiple choice questions related to control flow statements in C programming. Some key questions cover if-else conditional statements, switch statements, while and for loops, break and continue keywords, goto statements. The correct answers are provided for each question.

Uploaded by

mayande rohini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Control Flow Statements

1.
#include<stdio.h>
int main(void)
{
int one, two = 1, three;

if(three = (two == 0)); one = 5; two = 3;


printf("%d %d %d\n", three, two, one);

return 0;
}

A. 1 1 5
B. 0 3 garbage value
C. 0 1 5
D. 0 3 5

Answer: D

2.
#include<stdio.h>
int main(void)
{
int a = 1, b = 1, c;
if( c = b < 0) a = 5;
else if( b == 0) a = 7;
else a = 9;
printf("%d %d\n", a, c);
return 0;
}

A. 9 0
B. 7 0
C. 5 0
D. Compiler error
E. None of the above

Answer: A

February 2020 – Augest 2020 1


Control Flow Statements
3.
#include <stdio.h>
int main(void)
{
int y = 1;

if( y < 0)
if( y > 0);
printf("sunbeam pune\n");
else
printf("sunbeam karad\n");

return 0;
}

A. sunbeam pune
B. sunbeam karad
C. Nothing
D. Compiler time error
E. Run time error

Answer: D

4.
#include <stdio.h>
int main(void)
{
int x = 3, y = z = 4;
printf("%d\n", z >= y >= x ? 1 : 0);
return 0;
}

A. 0
B. 1
C. Compile time error
D. Runtime error

Answer: C

February 2020 – Augest 2020 2


Control Flow Statements
5.
#include <stdio.h>
int main(void)
{
int i=1,j=2;
switch(i)
{
default: printf("Sunbeam Pune");break;
case 1+1-1: printf("Sunbeam Karad ");
case 'j': printf("Sunbeam Market yard"); break;
}
return 0;
}

A. Sunbeam Pune
B. Sunbeam Karad
C. Sunbeam KaradSunbeam Market yard
D. Compiler time error
E. Run time error
Answer: C

6.
#include<stdio.h>
int main(void)
{
int x = 1, y = 1, z = 1;
printf("%d ", z += x < y ? x++ : y++);
printf("%d %d %d\n", x, y, z);
return 0;
}

A. 2 1 2 2
B. 2 2 1 2
C. 1 2 2 2
D. 2 2 2 1
E. 2 2 2 2

Answer: A

February 2020 – Augest 2020 3


Control Flow Statements
7.
#include <stdio.h>
int main(void)
{
int k=1;
switch(k++)
{
default : printf("0");
case 1: case 2:printf("2");
case 3*0: printf("1");
}
return 0;
}

A. 12
B. Compiler error
C. runtime error
D. 21
Answer: D

8.
#include <stdio.h>
int main(void)
{
float i=1.5;
switch((int)i)
{
case 1: printf("1");case 2:printf("2");
default : printf("0");
}
return 0;
}
A. 0
B. 1
C. Compiler error
D. 120
E. 2
Answer: D

February 2020 – Augest 2020 4


Control Flow Statements
9.
#include <stdio.h>
int main(void)
{
int i,t=4;
while(scanf("%d",&i)-t)
printf("%d-%d ",t--,i);
return 0;
} // Note : if the inputs are 0 1 2 3

A. 3-0 2-1 1-2


B. 4-0 3-1 2-2
C. 3-1 2-2 1-3
D. 4-1 3-2 3-3
E. 0-4 1-3 2-1 3-0

Answer: B

10.
#include <stdio.h>
int main(void)
{
unsigned int var = 1;

while(var-- > -2)


printf("PreCAT");
return 0;
}

A. 3 time preCAT
B. no output - exit value zero
C. Error
D. None of the above
E. no output - exit value other than zero

Answer: B

February 2020 – Augest 2020 5


Control Flow Statements
11.
#include <stdio.h>
int main(void)
{
int itr=0;
for(;itr++<0;printf("%d",itr)) ;
printf("%d",itr);
return 0;
}

A. 0
B. 1
C. Nothing
D. None of the above

Answer: B

12.
#include <stdio.h>
int main(void)
{
int j,val=9;
for(j=0;j++ <= 4;j++)
{
if(NULL) val = j;
else if(j%2==0) val = 1;
else val = 0;
}
printf("%d %d\n", j, val);
return 0;
}

A. 5 9
B. 5 1
C. 7 0
D. 7 9

Answer: C

February 2020 – Augest 2020 6


Control Flow Statements
13.
#include <stdio.h>
int main(void)
{
int i=1;
here:
i=010;

while (i<=5)
{
printf("%d",i);
if (i>2)
goto here;
i++;
}
printf("sunbeam");

return 0;
}

A. 12345
B. 123sunbeam
C. 123sunbeam45
D. sunbeam

Answer: D

14.
#include <stdio.h>
int main(void)
{
int j;

for(j=0;j++ <= 4;)


printf("j=%d ",j++);

return 0;
}

February 2020 – Augest 2020 7


Control Flow Statements
A. j=1 j=3 j=5
B. j=1 j=3
C. Compiler Error
D. None of the above

Answer: A

15.
#include <stdio.h>
int main(void)
{
int i=1,j=3;
do
{
switch(i)
{
case 2: j--;

default: while(j) j-- + 1; break;

case 1: i=j+1; j=j+1; break;

}while(j>=1);

printf("%d %d\n", i, j);

return 0;
}
A. 4 0
B. Infinite Loop
C. Compiler time error
D. None of the above

Answer: A

February 2020 – Augest 2020 8


Control Flow Statements
16.
#include <stdio.h>
int main(void)
{
int i;
i=printf("sunbeam")

for(;i >= printf("sunbeam"); printf("sunbeam"))


i-=1;

printf("sunbeam");
return 0;
}

A. sunbeam will be printed 6 times


B. sunbeam will be printed 5 times
C. sunbeam will be printed 4 times
D. sunbeam will be printed infinite times
E. Compile time error

Answer: B

February 2020 – Augest 2020 9

You might also like