Please Turn On Java Script To Access This Site.

C Institute | Questions


Previous Topic : Conditional Operator - 1Next Topic : sizeof operator - 1

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: 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 : c
Explanation : The expression is solved in this manner.
k=k+=(m<m ? m+=k : m+k);
mexpression will become k=k+=15
k+=15 yields 23 and finally k=23. and m is 7.
Learn Complete Concept Here


Q2: What will be the values of m and k ?
#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)  7 23
c)  15 15
d)  23 22
Correct Answer : a
Explanation : Due to operator precedence. Learn complete concept here


Previous Topic : Conditional Operator - 1Next Topic : sizeof operator - 1