Search Placementyogi.com
 

Decision control Structures in C objective questions

  :: Topics ::

1

What is the output of the following program?

#include<stdio.h>
void main()
{
        int a=8,b=4;
        int c,d;
        c= a>6;
        d= a>2 && b==3;
        printf("c = %d, d= %d",c,d);
}
A.

c= 1, d= 0

B.

c= 0, d= 0

C.

c= 0, d= 1

D.

Compilation Error

See Answer & Explanation Lets Discuss
Correct answer is : A
Explanation

Any Relational expression is evaluated in terms of TRUE or FALSE. TRUE is 1 and FALSE is 0.

In this case a>6 => 8>6 is TRUE, Hence c is 1.

d=a>2 && b==3

=> 8 >2 && 4==3

=> FALSE && 4==3 (Short Circuiting does not happen since first part is FALSE in this expression.)

=> FALSE && FALSE

=> 0 && 0 => 0.

Hence d= 0

 
2

What is the output of the following program?

#include<stdio.h>
void main()
{
   int i=10;
   switch(i)
   {
      case 1: printf(" i=1");
              break;
      case 10: printf(" i=10");
      case 11: printf(" i=11");
              break;
	  case 12: printf(" i=12");
    }
}
A.

i=10 i=11 i=12

B.

i=1 i=10 i=11 i=12

C.

i=10 i=11

D.

None of the Above

See Answer & Explanation Lets Discuss
Correct answer is : C
Explanation

Since i is equal to 10, the control directly jumps to the case 10 and executes:

printf(" i=10");

But after executing this line the compiler does not encounter break command hence the 

case 11 is also executed i.e. 

printf(" i=11");

After executing this line the compiler encounters break; and the control comes out of the switch block.

 

Point to remember: If a break statement is not encountered in a case block all the case blocks following the current case block are also executed serially until a break statement is found.

 
 
3

What is the output of the following program?

#include<stdio.h>
void main()
{
	char c = 'c';
	switch(c)
	{
		case 'a' : printf("inside case a,");
				   break;
		case 'b' : printf("inside case b,");
				   break;
		case 'c' : printf("inside case c,");
		case 'd' : printf("inside case d,");
				   continue;
		default: printf("inside default case");
				 break;
	}
}
A.

inside case c, inside case d

B.

inside case c

C.

inside case c, inside case d, inside default case

D.

Compilation Error

See Answer & Explanation Lets Discuss
Correct answer is : D
Explanation

The program throws a compilation error because we have used "continue"

statement inside switch which is not allowed.

Note: The continue statement can only be used inside a loop where it is used to skip the current iteration.

 
4

What is the output of the following program?

#include<stdio.h>
void main()
{
	char c= 'a';
	switch(c)
	{
		case 65 : printf("inside case A,");
				   break;
		case 97 : printf("inside case a,");
				   break;
		default: printf("inside default case");
				 break;
	}
}

 

A.

inside default case

B.

inside case a,

C.

Compilation Error

D.

inside case A,

See Answer & Explanation Lets Discuss
Correct answer is : B
Explanation

When we store a character into a character variable only ascii value is copied to the variable.

Here the ascii value of 'a' (97) is copied in to the character c.

Even though we pass a character inside the switch block it is evaluated as an integer and hence

"case 97" gets satisfied and "inside case a" is printed.

 
 
5

What is the output of the following program?

#include<stdio.h>
void main()
{
        int a=8,b=4;
        int c;
		c=(a<6) || (b=10);
        printf("\nc= %d, a=%d, b=%d",c,a,b);
}
A.

c= 1, b= 4

B.

c= 1, b= 10

C.

c= 0, b= 4

D.

Compilation Error

See Answer & Explanation Lets Discuss
Correct answer is : B
Explanation

Here, a< 6 is FALSE.

b=10 is an assignment expression which assigns 10 to b and  returns 10 (a NON-ZERO value) and hence is evaluated as TRUE.

We Know that :

FALSE || TRUE = TRUE 

Hence c=1 and b=10.

 
 

Banner to LogicGuns.com

Hide Page Information

Decision control Structures in C objective questions with answer and explanation, questions on if-else ladder in C and switch case in C switch(c) with example

Objective Questions on switch case in C

This section contains objective questions on switch case, and explains what happens if we do not use break inside switch case

Objective Questions on if else in C

This section contains objective questions on if else control structures in C

Objective Questions on decision making in C

This section contains objective questions on decision making in C

Here you can find C Decision Control Structures interview questions with answers and explanation.

What are C Decision Control Structures?

if else
switch

Placement objective and interview questions on conditional ?: operator

In this section you can learn and practice C Decision Control Structures (Questions with Answers) to improve your skills in order to face the interview, competitive examination and various entrance test (CAT, GATE, GRE, MAT, Bank Exam, Railway Exam etc.) with full confidence.

Where can I get C Decision Control Structures Objective Questions and Answers with Explanation?

PlacementYogi provides you lots of fully solved C Decision Control Structures questions and answers with explanation. Fully solved examples with detailed answer description, explanation are given and it would be easy to understand. All students, freshers can download C Decision Control Structures quiz questions with answers as PDF files and eBooks.

Where can I get C Decision Control Structures Interview Questions and Answers (objective type, multiple choice)?

Here you can find objective type C Decision Control Structures questions and answers for interview and entrance examination. Multiple choice and true or false type questions are also provided.

How to solve C Decision Control Structures problems?

You can easily solve all kind of questions based on C Decision Control Structures by practicing the exercises (including shortcut methods to solve problems) given below.