0% found this document useful (0 votes)
111 views20 pages

4) What Will Be The Output of The Following C Code?: #Include Void Main

The document contains multiple choice questions related to C programming concepts like loops, conditional statements, operators etc. The given code snippets are evaluated and the correct output is selected as the answer.
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
0% found this document useful (0 votes)
111 views20 pages

4) What Will Be The Output of The Following C Code?: #Include Void Main

The document contains multiple choice questions related to C programming concepts like loops, conditional statements, operators etc. The given code snippets are evaluated and the correct output is selected as the answer.
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/ 20

1) Choose the right output.

#include<stdio.h>
void main() {
int a= 10 + 4.867;
printf("a=%d", a); }

A) a=10
B) a=14.867
C)a=14
D) compiler error

2) Which of the below statements are true?

i) Struct is derived datatype


ii) Union is user-defined datatype
iii) ?: is ternary data type
iv) Unary operators have right to left associativity

A) 1, 2, 3, 4
B) 2, 3, 4
C) 1, 2, 3
D) 2, 3

3) For c=2, value of c after c<<=1 is?

A) c=1
B) c=2
C) c=3
D) c=4

4)What will be the output of the following C code?

#include <stdio.h>
void main()
{
int i = 0, k=0;
if (i == 0)
goto label;
for (;k < 3; k++,i++)
{
printf("hi ");
label:printf("%d", i);
}
}

a) 0 b) hi hi hi 0 1 2
c) 0hi 1hi 2 d) 0 0 0
5)Find the output of the following code:
#include<stdio.h>
int main()
{
float a=15.3;
int b=3;
printf("%d",a%b);
}

E) 3 B)0
C)Error D)None of the above

6)What will the following code print?


#include <stdio.h>
void main()
{
int a=2;
int b=++a -a;
printf("%d\n",b);
printf("%d %d %d",b,b++,++b);
}
A)0 B)0
002 0 11

C)0 D)0
012 2 12

7)Find the outputs for the following code?


i)
#include<stdio.h>
void main()
{
int a=5;
int b=5;
int c=0;
if((++a == b++) && (a++ - --b ==1 ))
c=9;
printf("%d %d %d",a,b,c);
}

A) 7 5 9 B)7 5 0
C)6 6 9 D)6 6 0
8)
What is the output of the following code?
#include<stdio.h>
int main()
{
int a=0.9;
if(a<0.9)
printf("yes");
else
printf("no");
return 0;
}

9).Write the output of the following program

#include <stdio.h>
int main(void)
{
int a=92, b=98, c=67;
if (a > b)
{
if (a > c)
{
printf("%d \n",a);
}
else
{
printf("%d \n",c);
}
}
else if (b > c)
{
printf("%d \n",b);
}
else
{
printf("%d \n",c);
}
return 0;
}

A) 92 B) 67
C) 98 D) Compilation Error

10.
Write the output of the following program

#include <stdio.h>
void main()
{
int x=50;
if(x=18)
printf("TRUE");
else
printf("FALSE");
}

A) True B) False
C) Error D) None

11) Write the output of the following program


#include<stdio.h>
int main()
{
int k, j;
for(k=1, j=10; k <= 5; k++)
{
printf("%d", (k+j));
}
A) Infinite loop B)17
C)Compilation error D)11 12 13 14 15 16

12) Which of the following are incorrect statements? If int a=10.


1) if( a==10 ) printf("Hello");
2) if( 10==a ) printf("Hello");
3) if( a=10 ) printf("Hello");
4) if( 10=a ) printf("Hello");

A)2 and 4 B) 3 only


C) 4 only D) 2,3 and 4
13)Which looping process checks the test condition at the end of the loop?

B) for Loop B) while Loop


C) do-while loop D) No looping process tests at the end

14)Choose a correct C do while syntax.

C) dowhile(condition) B) do while(condition)
{ {
//statements } //statements }

C) do D) do
{ {
//statements //statements
}while(condition) }while(condition);
15)What will be the output of the following C code?

#include <stdio.h>
int main()
{
printf("%d ", 1);
goto l1;
printf("%d ", 2);
l1:goto l2;
printf("%d ", 3);
l2:printf("%d ", 4);
}

a) 1 4 b) Compilation error
c) 1 2 4 d) 1 3 4

16)Write the output of the following program


#include<stdio.h>
void main()
{
int i, sum = 0;
for (i = 1; i <= 10; i++)
if (i%2 == 0)
sum += i;
printf ("%d",sum);
}

A) 0 B) 30
C) 40 D) 20
17)How many times does “Hi” get printed?

#include <stdio.h>
void main()
{
int i = 0;
int j = 0;
for (i = 0;i < 5; i++)
{
for (j = 0;j < 4; j++)
{
if (i != 1)
continue;
printf("Hi \n");
}
}
}

A)16 B)4
C)20 D)8

18)Write the output of the following program

#include <stdio.h>
int main()
{
int a = 10;
do
{
printf("%d ", a);
a = a + 1;
}while(a<14);
return 0;
}
A)10 11 12 13 B)11 12 13 14
C)10 11 12 13 14 D)11 12 13 14 15

19)What would be the output of the following program if its input is 2.

#include <stdio.h>
int main()
{
int i=1, number=0;
scanf("%d",&number);
do
{
printf("%d ", (number*i));
i++;
}while(i<=5);
return 0;
}

A)1 2 4 6 8 B)2 4 8 16 32
C)2 4 6 8 10 D)1 3 5 7 9
20)Write the output of the following program

#include<stdio.h>
int main()
{
int n;
for (n = 9; n!=0; n--)
printf("n = %d", n--);
return 0;
}

A) 9 7 5 3 1 B) 9 8 7 6 5 4 3 2 1
C) Infinite loop D) 9 7 5 3

21)Write the output of the following program

#include <stdio.h>
void main()
{
int i,j,charVal='A';
for(i = 5;i >= 1;i--)
{
for(j=0;j< i;j++)
printf("%c ",(charVal+j));
printf("\n");
}
}

D) A B C D E B) A B C D
A B CD E ABCD
A B CD E ABCD
A B CD E ABCD
ABCDE

C) A B C D D) A B C D E
ABC AB CD
AB ABC
A AB
A

22)Write the output of the following program

#include <stdio.h>
void main()
{
int i;
for(i=0;i<10;++i)
{
printf("#");
if(i>6)
continue;
printf("%d",i);
}
}
A) #0#1#2#3#4#5#6###
B) #0#1#2#3#4#5#6#7#8#9#10
C) #0#1#2#3#4#5##7#8#9#10
D) #0#1#2#3#4#5#

23)
What is the output of the following code?
#include<stdio.h>
int main()
{
int a=1+2*3%4/5-6;
int b=a>10?100:50;
printf("%d %d",a,b);
}

24)
3) Choose a correct statement about C break; statement.?
A) break; statement can be used inside switch block
B) break; statement can be used with loops like for, while and do while.
C) A single break; statement can force execution control to come out of only one loop.
D) All the above.

25)
How many times does N get printed in the following code?
#include<stdio.h>
int main()
{
int i=1;
while(i<10)
{
printf("N");
i++;
if(i==5) break;
}
return 0;
}
A)0 B)8
C)4 D)9

26)
What will be the output of the following C code?
#include <stdio.h>
int main()
{
while ()
printf("In while loop ");
printf("After loop\n");
}

a) In while loop after loop


b) After loop
c) Compile time error
d) Infinite loop
27)Which of the following are infinite loops?

(1)
for( ; ; )
printf("SGC is chill :))");

(2) (3)
#include <stdio.h> #include <stdio.h>
int main() int main()
{ {
int i=0; int i=1;
while(1) while(i<=10);
{ {
i++; printf("%d", i);
printf("i is :%d",i); i++;
} }
return 0; return 0;
} }

Options:
A) Only 1
B) Both 1 and 2
C) All of the above
D) None of the above

28)
#include<stdio.h>
int main()
{
int a=5;
switch(a)
{
case 0: printf("0 ");
break;
case 3: printf("3 ");
break;
case 5: printf("5 ");
break;
default: printf("RABBIT ");
break;
}

a=3;
switch(a)
{
case 0: printf("0 ");
case 3: printf("3 ");
case 5: printf("5 ");
default: printf("RABBIT "); break;
}

return 0;
}
A) 5 RABBIT
B) 5 3
C) 0 3 5 RABBIT RABBIT
D) 5 3 5 RABBIT
29)What will be the output of the following C code?

#include <stdio.h>
void main()
{
int i = 0, k=0;
if (i == 0)
goto label;
for (;k < 3; k++,i++)
{
printf("hi ");
label:printf("%d", i);
}
}

a) 0 b) hi hi hi 0 1 2
c) 0hi 1hi 2 d) 0 0 0

You might also like