0% found this document useful (0 votes)
4 views9 pages

MCQ-1 Condition

The document contains multiple-choice questions (MCQs) related to C programming, specifically focusing on the behavior of conditional statements and switch cases. Each question presents a code snippet and asks for the expected output or comments on the code. The questions cover various scenarios, including variable initialization, control flow, and syntax errors.

Uploaded by

catalyststore01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views9 pages

MCQ-1 Condition

The document contains multiple-choice questions (MCQs) related to C programming, specifically focusing on the behavior of conditional statements and switch cases. Each question presents a code snippet and asks for the expected output or comments on the code. The questions cover various scenarios, including variable initialization, control flow, and syntax errors.

Uploaded by

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

(Page 1 of 9)

MCQ-1 Condition

1. The output of the code below is


int x = 5;
if (x < 1)
printf("hello");
if (x == 5)
printf("hi");
else
printf("no");
a) hi
b) hello
c) no
d) None of the mentioned

2. The output of the code below is


int x;
int main(){
if (x)
printf("hi");
else
printf("how are u");
return 0;
}
a) hi
b) how are you
c) Compile time error
d) None of the mentioned

3. Comment on the following code below


int x = 5;
if (true);
printf("hello");
a) It will display hello
b) It will throw an error
c) Nothing will be displayed
d) Compiler dependent

4. The output of the code below is


int x = 0;
if (x == 0)
printf("hi");
else
printf("how are u");
printf("hello");
a) hi
(Page 2 of 9)

b) how are you


c) hello
d) hihello

5. The output of the code below is


int x = 5;
if (x < 1);
printf("Hello");
a) Nothing
b) Run time error
c) Hello
d) Varies

6. The output of the code below is(when 1 is entered)


float ch;
printf("enter a value btw 1 to 2:");
scanf("%f", &ch);
switch (ch)
{
case 1:
printf("1");
break;
case 2:
printf("2");
break;
}
a) Compile time error
b) 1
c) 2
d) Varies

7. When 1 is entered, The output of the code below is?


int ch;
printf("enter a value btw 1 to 2:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("1 ");
default:
printf("2 ");
}
a) 1
b) 2
c) 1 2
d) Run time error
(Page 3 of 9)

8. When 2 is entered, The output of the code below is?


int ch;
printf("enter a value btw 1 to 2:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("1");
break;
printf("Hi");
default:
printf("2");
}
a) 1
b) Hi 2
c) Run time error
d) 2

9. What is the output of this C code?


int x = 1;
if (x > 0)
printf("inside if\n");
else if (x > 0)
printf("inside elseif\n");
a) inside if
b) inside elseif
c) inside if
inside elseif
d) Compile time error

10. What is the output of this C code?


int x = 0;
if (x == 1)
if (x == 0)
printf("inside if\n");
else
printf("inside else if\n");
else
printf("inside else\n");
a) inside if
b) inside else if
c) inside else
d) Compile time error

11. What is the output of this C code?


int x = 0;
if (x == 0)
(Page 4 of 9)

printf("true, ");
else if (x = 10)
printf("false, ");
printf("%d\n", x);
a) false, 0
b) true, 0
c) true, 10
d) Compile time error

12. What is the output of this C code?


int x = 0;
if (x == 1)
if (x >= 0)
printf("true\n");
else
printf("false\n");
a) true
b) false
c) Depends on the compiler
d) No print statement

13. Comment on the output of this C code?


int a = 1;
if (a)
printf("All is Well ");
printf("I am Well\n");
else
printf("I am not a River\n");
a) Output will be All is Well I am Well
b) Output will be I am Well I am not a River
c) Output will be I am Well
d) Compile time errors during compilation

14. What is the output of this C code(When 1 is entered)?


char ch[20]; //for string
printf("enter a value btw 1 to 3:");
scanf("%s", ch); //%s for string
switch (ch)
{
case "1":
printf("1");
break;
case "2":
printf("2");
break;
}
a) 1
(Page 5 of 9)

b) Compile time error


c) 2
d) Run time error

15. What is the output of this C code?


int a = 1, b = 1;
switch (a)
{
case a*b:
printf("yes ");
case a-b:
printf("no\n");
break;
}
a) yes
b) no
c) Compile time error
d) yes no

16. What is the output of this C code?


int x = 97;
switch (x)
{
case 'a':
printf("yes ");
break;
case 97:
printf("no\n");
break;
}
a) yes
b) yes no
c) Duplicate case value error
d) Character case value error

17. What is the output of this C code?


float f = 1;
switch (f)
{
case 1.0:
printf("yes\n");
break;
default:
printf("default\n");
}
a) yes
b) yes default
(Page 6 of 9)

c) Undefined behaviour
d) Compile time error

18. What is the output of this C code?


const int a = 1, b = 2;
int main()
{
int x = 1;
switch (x)
{
case a:
printf("yes ");
case b:
printf("no\n");
break;
}
}
a) yes no
b) yes
c) no
d) Compile time error

19. What is the output of this C code?


switch (printf("Do"))
{
case 1:
printf("First\n");
break;
case 2:
printf("Second\n");
break;
default:
printf("Default\n");
break;
}
a) Do
b) DoFirst
c) DoSecond
d) DoDefault

20. Comment on the output of this C code?


int a = 1;
switch (a)
case 1:
printf("%d", a);
case 2:
printf("%d", a);
(Page 7 of 9)

case 3:
printf("%d", a);
default:
printf("%d", a);
a) No error, output is 1111
b) No error, output is 1
c) Compile time error, no break statements
d) Compile time error, case label outside switch statement

21. Switch statement accepts.


a) int
b) char
c) long
d) All of the mentioned

22. Comment on the output of this C code?


int a = 1;
switch (a)
{
case a:
printf("Case A ");
default:
printf("Default");
}
a) Output: Case A
b) Output: Default
c) Output: Case A Default
d) Compile time error

23. int i = 4;
switch(i)
{
default:
printf(“Matrix”);
case 1:
printf(“Computer”);
break;
case 2:
printf(“Education”);
break;
case 3:
printf(“Hello”);
}
a. Compile Time Error
b. Matrix
c. MatrixComputer
d. Hello
(Page 8 of 9)

24. int i =4;


switch (i)
{
}
printf(“Hello World”);
a. Compile Time Error
b. No Output
c. Hello World
d. None of these

25. int i =1;


switch (i)
{
printf(“Matrix”);/*common for both
cases*/
case 1:
printf(“Hello”);
break;
case 2:
printf(“Bye”);
break;
}
a. Matrix Hello
b. Matrix Bye
c. Hello Bye
d. Hello

26. char card = 3;


switch(card)
{
case 1:
printf(“King”);
case 2:
printf(“Queen”);
default:
printf(“Jokar”);
}
printf(“ You have losing the game:”);
a. King
b. Jokar You have losing the game:
c. No Output
d. Jokar

27. int k;
float j = 2.0;
switch(k = j+1)
(Page 9 of 9)

{
case 3:
printf(“you have passed:”);
break;
default:
printf(“Leave It”);
}
a. Error because j is float.
b. You have passed:
c. Leave it
d. No output

28.
int a=500,b,c;
if(a>=400)
b=300;
c=200;
printf(“%d %d”,b,c);
a. 300 200
b. garbage 200
c. garbage garbage
d. error else is missing

29. int x =10,y =20;


if(x == y);
printf(“%d %d”,x,y);
a. no output
b. compilation error
c. 10 20
d. garbage

30. int ch = ‘a’+ ‘b’ ;


switch(ch)
{
case ‘a’:
case ‘b’:
printf(“you have secured a”);
case ‘A’:
printf(“you are confused:”);
case ‘b’ + ‘a’:
printf(“you have secured both a and b:”);
}
a. you have secured both a and b:
b. you have secured a
c. error
d. no output

You might also like