Search Placementyogi.com

Operators in C Objective Questions and Answers

:: Topics ::

 1 What is the output of the following program? ```#include void main() { int a=6,b=5,c=4; printf("%d",(a>b>c?1:0)); }``` A. 1 B. 0 C. Error D. None of the Above
See Answer & Explanation Lets Discuss
Explanation

Here, the expression a>b>c is evaluated as:

(a>b)>c

= (6>5)>4 which becomes 1>4 which is FALSE.

Hence the output is 0.

Now, a few lines about Ternary operator(?:)

Let us consider an expression

Result=(W>X) ? Y : Z,

If the expression (W>X)is TRUE then the Result = Y else Result = Z.

 2 What is the output of the following program? ```#include void main() { printf("32%5=%d",32%5); printf("\n32%-5=%d",32%-5); printf("\n-32%5=%d",-32%5); printf("\n-32%-5=%d",-32%-5); }``` A. 32%5=2 32%-5=2 -32%5=-2 -32%-5=-2 B. 32%5=2 32%-5=-2 -32%5=-2 -32%-5=2 C. 32%5=2 32%-5=-2 -32%5=-2 -32%-5=-2 D. 32%5=2 32%-5=3 -32%5=-2 -32%-5=-2
See Answer & Explanation Lets Discuss
Explanation

In C , when you use modulus operator and the operands are signed values,

The signs are ignored while evaluating the remainder and then after getting the remainder, the sign of the numerator is assigned to the remainder.

Hence, -32%5 is -2 and -32%-5 is also -2 , as the sign of numerator(-32) is -ve.

In case of 32%-5 the answer is +2 because the 32 is a +ve number even though the denominator is -ve.

 3 What is the output of the following program? ```#include void main() { float f=0.1; char c='a'; double d=0.456; f++; c++; d++; printf("%f %c %f\n",f,c,d); }``` A. 0.2 b 0.556 B. 1.1 b 1.456 C. 1.100000 b 1.456000 D. Compilation Error: Increment operator can not be used with these data types.
See Answer & Explanation Lets Discuss
Explanation

Increment operator works perfectly with float, double and char data types.

Increment operator simply means increment by 1.(Except in the case of pointers, where it increments my the size of datatype pointed by the pointer)

Hence, 0.1 became 1.1 and since we know that when a float is printed there should be six digits after the decimal, Hence

1.100000 is printed.

Same is the case with variable of "double" datatype, So, 1.456000 is printed.

A character is nothing but an ASCII code. Hence , 'a' whose ASCII code is 97 incremented by 1

and becomes 98 which is the ASCII code for 'b'. The format specifier is %c so the character 'b' is printed.

 4 What is the output of the following program? ```#include int main() { int a=2; a=a+2<<1; printf("%d ",a); a=a+(2<<1); printf("%d",a); }``` A. 8 8 B. 8 12 C. 6 6 D. 2 3
See Answer & Explanation Lets Discuss
Explanation

The precedence of + is more than << (left shift operator).

Consider the expression:  a=a+2<<1;

Hence , the above expression is (a+2)<<1

4<<1

i.e. 8  (Left Shift Doubles the value)

Now, a=8

In the second statement: a=a+(2<<1)

The Left shift operator executes before, So a=a+4= 8+4=12

Hence the answer is 8 12

Hide Page Information

Objective Questions on operators in C with Answers

Why Operators in C?

In this section you can learn and practice Operators in C (Questions with Answers) to improve your skills in order to face the interview, competitive examination and various entrance test of TCS, Infosys, Wipro, Coznizant interview with full confidence.

Where can I get Operators in C Questions and Answers with Explanation?

PlacementYogi provides you lots of fully solved Operators in C 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 Operators in C quiz questions with answers as PDF files and eBooks.

Where can I get Operators in C Interview Questions and Answers (objective type, multiple choice)?

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

How to solve Operators in C problems?

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