Please Turn On Java Script To Access This Site.

C Institute | Questions


Previous Topic : Increment Decrement Operator - 2Next Topic : Conditional Operator - 2

This section on C interview questions, tricky questions, and puzzles focuses on “Conditional operator”. One shall practice these questions and puzzles to improve their C programming skills needed for various interviews (campus interviews, walk-in interviews, viva exams and company interviews), placements, entrance exams and other competitive exams. These programming questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate, engineering student, bca student, mca student, mcs students or an experienced IT professional. Here is a listing of C questions and puzzles on “Conditional operator” along with answers and/or explanations.

Q1: Conditional Operator (?:) is a ______________ operator.
a)  Unary
b)  Binary
c)  Ternary
d)  None of these
Correct Answer : c
Explanation : The ? : is a ternary operator, because it have three operands.


Q2: What will be the output of the following C code?

#include <stdio.h>
int main()
{
     int a = 10, b = 0;
     int c = (a++, b++) ? b : a;
     printf("%d ", c);
     return 0; }
a)  10
b)  11
c)  1
d)  0
Correct Answer : b
Explanation : Watch explanation Conditional Operator Interview Questions Solution


Q3: What will be the output of the following c code?
#include <stdio.h>
void main()
{     int k = 8;
    int m = 7;
    k=(k+=m<m) ? m+=k : m+k;
    printf("%d %d",m,k);
}
a)  7 22
b)  15 15
c)  7 23
d)  None of these
Correct Answer : b
Explanation : Order of evaluation of operators in the expression is
  1. ( )
  2. ? :
  3. =
Learn c free :


Previous Topic : Increment Decrement Operator - 2Next Topic : Conditional Operator - 2