Font size
WorksheetsDecision and Case Control Statements in C
Total questions: 35
Worksheet time: 18mins
What will be the output of the following C code?
#include <stdio.h>
void main()
{
int x = 5;
if (x < 1)
printf("hello");
if (x == 5)
printf("hi");
else
printf("no");
}
hi
hello
no
error
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = 0;
if (x == 1)
if (x == 0)
printf("inside if\n");
else
printf("inside else if\n");
else
printf("inside else\n");
}
inside if
inside else if
inside else
compile time error
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = 0;
if (x == 1)
if (x >= 0)
printf("true\n");
else
printf("false\n");
}
Depends on the compiler
No print statement
True
False
The output of the following segment is
int k, n=20;
k=(n>5?(n<=10?100:200):500);
printf("%d",n);
100
200
300
20
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int a = 1, b = 1;
switch (a)
{
case a*b:
printf("yes ");
case a-b:
printf("no\n");
break;
}
}
yes
no
yes no
compile time error
What is the result after execution of the following code if a is 10, b is 5, and c is 10?
if ((a > b) && (a <= c))
a = a + 1;
else
c = c+1;
a = 10, c = 10
a = 11, c = 10
a = 10, c = 11
a = 11, c = 11
Output of the following code
#include <stdio.h>
int main()
{ int i = 0;
switch (i)
{
case '0': printf("Geeks");
break;
case '1': printf("Quiz");
break;
default: printf("GeeksQuiz");
}
return 0;
}
Geeks
Quiz
GeeksQuiz
None of the above
How will you print \n on the screen?
printf("\n");
echo "\\n";
printf('\n');
printf("\\n");
int main()
{
if(0);
printf("Hello");
printf("Hi");
return 0;
}
Hi
Hello
HelloHi
Compilation Error
what is output of following code?
#include <stdio.h>
int main( )
{
if(printf("C programming is"))
{
printf("Easy");
}
else
{
printf("Hard");
}
return 0;
}
C Programming Easy
Easy
Hard
None of these
Find Error/ output in following code
Void main ()
{
int a= 1, b= 2, c = 3;
Char d = 0;
if (a,b,c,d)
{
printf ( " EXAM") ;
}
}
No output and No error
EXAM
Runtime Error
Compile time error
Find Error/ output in following code
Void main ()
{
printf ( " % d " , printf ( " computer science"));
}
Computer science16
16computer science
Computer science
Computer science18
What will be the output of the program?
int main ()
{
printf ( 5+"Good Morning\n");
return 0;
}
Good Morning
Good
M
Morning
What happens to the code in the body of an "if" statement if the condition is false?
The computer determines if it is essential to the program and if it is, then the code is executed anyway.
The code moves to a coastal city, attempting to find love and start a family. However, low waged and crushing mortgage rates lead to it moving back home where it sits, hoping that one day it will be executed.
The code is skipped.
The code stages a revolution and attempts to take over the program, ultimately unsuccessfully, which leads to it not being executed.
what is the ouput of the below program?
int main()
{
int i=10, j=20;
if((i=100) && (j==20))
{
printf("Have a nice day");
}
else
{
printf("condition not true");
}
return 0;
}
No output
Have a nice day
condition not true
Complier Error
What is the output ?
int var;
var = !(0 && (2||1));
printf("%d",var);
0
2
1
Compiler Error
Char 65
Integer 65
Bye
Compilation Error
Bye
Integer
Char
Compilation Error
case 2 executed
case 1 executed
default block executed
Compilation Error
case 1 executed
case 1 executed case 2 executed
case 2 executed
Compilation Error
Compilation Error
case 1 executed
case 2 executed
default block executed
Switch ON the fan
Switch ON the Air Cooler
Save Energy
Compilation Error
First
Bye
Second
Compilation Error
Hai. This is case 3
Hai. This is case 6
Infinite Execution
Hai. This is default
25L
25.0
Compilation Error
Nothing
case one
case two
default block
Compile Time Error
inside default
FALSE
TRUE
Compilation Error
inside case
inside default
Prints Nothing
Compilation Error
inside case 1
inside case 3
inside case 4
inside case 7
inside case 1
inside case 3
inside case 4
inside case 7
Hai. This is case 0 Hai. This is case 1
Hai. This is case 0 Hai. This is case 2
Hai. This is case 0 Hai. This is case 1 Hai. This is case 2
Hai. This is case 0 Hai. This is default
Runtime Error
Hai default
Compilation Error
Hai default Hai case 1 Hai case 2 Hai case 3
What does the following code fragment write to the monitor?
Under
Over
Under the limit
Over the limit
What does the following code fragment write to the monitor?
Under
Over
Under the limit
Over the limit
