[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

C Programming :: Control Instructions - Discussion

Home > C Programming > Control Instructions > MCQs Questions Discussion

3 / 33

What is the output of the following 'C' program?

#include<stdio.h>
void main()
{
int i=10,j=20;
j=i,j?(i,j)?i:j:j;
printf("%d %d",i,j); 
}

A10 10

B10 20

C20 10

DCompilation Error

Answer: Option (Login/Signup)

Show Explanation

  1. notice the comma operator when variables are separated by them they are evaluated from left to right and only last value is considered ( it has less precedence than assignment operator)
    so due to the precedence of assignment being high the assignment is done first and then comma operator is evaluated be the expression finally evaluates to j=i,(j?(i,j)?i:j:j);
  2. so the value of i is assigned to j
    you can run the same program  with one more variable C the value of j will be equal to the value of C as per above logic

#include

void main()

{

int i=10,j=20;

int c=10000;

j=c,j?(i,j)?i:j:j;

printf("%d %d",i,j);

}


Asked In ::

Post Your Answer Here:     

Reply    
Rate This: +0 -0
    Report


Report Error

Please Login First Click Here