Decision Making
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
int num = 6;
if (num < 2)
printf("Hello");
if (num == 6)
printf("Hey");
else
printf("No");
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
None of these
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
switch (printf("Show\n"))
{
case 1:
printf("Option:First\n");
break;
case 2:
printf("Option:Second\n");
break;
default:
printf("Option:Default\n");
break;
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
Show
Option:Default
- Which of the following is the correct output for the program given below?
#include <stdio.h>
int main ()
{
int a = 400, b, c;
if ( a >= 500)
b = 400;
c = 300;
printf ( "%d %d %d \n" , a, b, c);
return 0;
}
-
View Hint View Answer Discuss in Forum
if( a >= 500) is equivalent to if(false).
Correct Option: C
if( a >= 500) is equivalent to if(false).
So the initialization of b will never be done.
Output
400 Garbage 300
- Which of the following statement are correct about the program given below?
#include <stdio.h>
int main ( )
{
int a = 40, b = 50;
if ( a == b )
printf ("a is equal to b \n");
elseif (a > b)
printf ("a is greater than b\n");
elseif (a < b)
printf ("a is less than b\n");
return 0;
}
-
View Hint View Answer Discuss in Forum
To make the program work replace 'elseif' with 'else if.
Correct Option: A
To make the program work replace 'elseif' with 'else if.
- Which of the following is the correct output for the program given below ?
#include <stdio.h>
int main ( )
{
int k = 5;
switch (k)
{
case 1:
printf ("Good Morning\n");
case 2:
printf ("Good Evening\n");
break;
case 3:
continue;
default:
printf ("Bye\n");
}
return 0;
}
-
View Hint View Answer Discuss in Forum
Continue should be used within a loop.
Correct Option: A
Continue should be used within a loop.
'Misplaced Continue'