Search Placementyogi.com
 

Decision control in C Advanced objective questions

  :: Topics ::

1

What is the output of the following program?

#include<stdio.h>
void main()
{
	float x=0.5;
	if (x < 0.5)
		printf("TRUE");
	else
		printf("FALSE :-( ");
}
A.

TRUE

B.

FALSE :-(

C.

Compilation Error

D.

None of the Above

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

The Output comes as a Surprise to almost all of us and is hard to believe yet the fact is:

Due to precision considerations a value slightly lesser that 0.5 is assigned to x and hence

when we compare it with 0.5 the result is FALSE.

 
 
2

What is the ouput of Program1.c and Program2.c

Program1.c
#include<stdio.h>
void main()
{
        int x=10,y;
        x=((x>5) ? (printf("\nPlacement"),printf("Yogi"),y=50): printf("\n rocks!!"));
		printf(" y=%d",y);
}
Program2.c
#include<stdio.h>
void main()
{
        int x=10,y;
        x=((x>5) ? (printf("\nPlacement");printf("Yogi");y=100;): printf("\n rocks!!"));
		printf(" y=%d",y);
}
A.

Program1: PlacementYogi y=50, Program2: Compilation Error

B.

Program1: Compilation Error, Program2: PlacementYogi y=100

C.

Program1: PlacementYogi y=50, Program2: PlacementYogi y=100

D.

Program1: Compilation Error, Program2: Compilation Error

E.

Program1: PlacementYogi y=50, Progam2: rocks!!

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

In a Ternary Operator Multiple statements are also allowed but are written in a completely different way.

It has "," (comma) as the separator between expressions. Hence the Program1.c is correct and prints PlacementYogi y=50.

 

In case of Program2.c

         x=((x>5) ? (printf("\nPlacement");printf("Yogi");y=100;): printf("\n rocks!!"));

The moment a semi-colon ";" is encountered in a statement it is interpreted as the end of the statement and hence throws the following compiler error:

error: expected ‘)’ before ‘;’ token

as the compiler could not find a matching closing bracket ")".

 
 

Banner to LogicGuns.com

Hide Page Information

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

tough difficult objective questions on switch case in C

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

tough difficult objective questions on if else in C

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

tough difficult objective questions on decision making in C

This section contains tough difficult 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 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.