0% found this document useful (0 votes)
147 views

Quiz 2 Inputs

The document contains 15 code snippets with multiple choice questions testing conditional statements, operators, and basic C programming concepts. The code snippets cover if/else statements, logical operators, switch statements, comparison operators, printf formatting, and increment/decrement operators. The correct answers provided test an understanding of how these basic programming constructs work in C code.

Uploaded by

Bhasker Rao
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views

Quiz 2 Inputs

The document contains 15 code snippets with multiple choice questions testing conditional statements, operators, and basic C programming concepts. The code snippets cover if/else statements, logical operators, switch statements, comparison operators, printf formatting, and increment/decrement operators. The correct answers provided test an understanding of how these basic programming constructs work in C code.

Uploaded by

Bhasker Rao
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1)#include<stdio.

h>
int main()
{
int a = -2;
if(a)
{
printf("Hello");
}
else{
printf("Hai");
}
return 0; }
a)Hello
b)Hai
c)Error
d)None of these
ANSWER:
A
2)#include<stdio.h>
int main()
{
if(0)
{
printf("x");
}
printf("y");
printf("z");
return 0;
}
a)x
b)y
c)xy
d)yz

Answer: D
3)#include<stdio.h>
int main()
{
if(5%5);
{
printf("x");
printf("y");
}
printf("z");
return 0;
}
a) z
b) xyz
c) xy
d) Compile time error

Answer:
C
4)#include <stdio.h>
int main()
{
int x = 0;
if (x == 0)
printf("hi");
else
printf("how are u");
printf("hello");
return 0;
}

a)hi
b)how are you
c)hello
d)hihello
Answer: C
5)
#include <stdio.h>
int main()
{
int i = 0;
switch (i)
{
case '0': printf("Hello");
break;
case '1': printf("world");
break;
default: printf("Helloworld");
}
return 0;
}
a) Hello
b) world
c) Helloworld
d) None of these
Answer: C
6)#include <stdio.h>
int main()
{
int i = 3;
switch (i)
{
case 0+1: printf("Welcome");
break;
case 1+2: printf("Hello");
break;
default: printf("Hai");
}
return 0;
}

a)Welcome
b)Hello
c)Hai
d)Error

7) #include<stdio.h>
void main() {
int a=11,b=5;
if(a=5) b++;
printf("%d %d", ++a, b++);
}
A. 12 7
B. 5 6
C. 6 6
D. 6 7 ANSWER : C
8) #include<stdio.h>
int main()
{
int i = 5, j = 6, k = 7;
if(i > j == k)
printf("%d %d %d", i++, ++j, --k);
else
printf("%d %d %d", i, j, k);
return 0;
}
A)6 7 8
B) 5 6 6
C)5 6 8
D)5 6 7
ANSWER : D
9) #include <stdio.h>
void main() {
float num=5.6;
switch(num)
{
case 5:printf("5");
case 6:printf("6");
default : printf("0");
break; }
printf("%d", num);
}
A)5
B)6
C)5 6 0
D) ERROR
ANSWER: D
10) #include<stdio.h>
int main()
{
if(sizeof(0))
printf("Hai");
else
printf("Bye");
return 0;
}
A)bye
B)hai
c)Hai bye
d)error
Answer: B
11)
#include <stdio.h>
int main()
{     int i;
    if (printf("0"))
        i = 3;
    else
        i = 5;
    printf("%d", i);
    return 0;
}
A)0 5
B)0 3
C) 0 0
D)0 3 5
Answer: B
12)
#include<stdio.h>
int main(){
float me = 5.25;
double you = 5.25;
if(me == you)
printf(“India is great");
else
break;
return 0;
}
A. Prints Nothing
B. India is great
C. Runtime Error
D. Compilation Error

Answer: D

13) #include<stdio.h>

int main(){
int i = 25;
if(i == 25);
i = 50;
if(i == 25)
i = i + 1;
else
i = i + 1;
printf("%d", i);
return 0;
}
a)25
b)50
c)51
d)none
Answer: C
14) #include<stdio.h>

int main(){
if("May I Get in")
printf("yes, Get in");
else
printf("No");
return 0;
}
A) May I Get in
B) yes, Get in
C) No
D) None

ANSWER : C
15)#include<stdio.h>
int main(){
int i = 0, j = 0;
if(i++ == j++)
printf("%d %d", i--, j--);
else
printf("%d %d", i, j);
return 0;
}
A. 0 0
B. 0 1
C. 1 0
D. 1 1
Answer : D

You might also like