The Gateway to Computer Science Excellence
0 votes

What is the output of this program?

int main(void)

int a = 10, b = 20, c = 30;
printf(" %d..%d..%d ", a+b+c, (b = b*2), (c = c*2));
return 0;
(A) 60..40..60
(B) 110..40..60
(C) 110..20..30
(D) 60..20..30

does sequence point comes into picture here?

in Programming by Boss (17.8k points)
retagged by | 108 views
Even I am a bit confused on this. You might have seen my comment on the forum. It would be better to ask Sir directly to clarify the doubt
yes i have messaged sir regarding this. let him reply. I have seen ur post. i am also confused :(

As per my knowledge,

printf is a function ===> comma is a separator but not operator, if comma is operator it is sequence point.

i have messaged sir regarding this

is it Arjun sir?

Yes exactly , here comma is not an operator. So I don't think there is any confusion with sequence point over here. Moreover no variable is getting updated more than once
since comma is not an operator here that is why ambiguity is here na??
kiran sir

In find it kind of similar to

Also read this :


since comma is not an operator here that is why ambiguity is here na??

yes... it is depend upon order of evaluation of parameters of function, it is also undefinded in C ===> this question lead to undefined behavior 


@sushmita what you have concluded from your sir 

1 Answer

0 votes
For printf() the sequence point is defined from right to left. Evaluation starts from right to left . But there is lot of debate going on regarding this at all the platforms. I have seen this type of questions even in C++,where it was cout statement. So , Just go with right to left evaluation .

I have followed this.

So , the answer will be option B) when right to left is considered the order of evaluation .
by Active (1.3k points)

Just go with right to left evaluation. Any source for this??

In general order of evaluation of function arguments is not defined right?


Generally when we pass arguments to the function they are just the value and not the expressions.

If we pass the expressions then we will known the difference in the order of evalutation.

Here is an example where the order of evaluation matters.


#include <stdio.h>
void function(int a ,int b, int c)

int main()
    int a=10;
    int b=20;
    int c=30;

the O/p of this is: 510..200..300

here also the order of evaluation of the expression is from right to left.




There's no source which says that it is right to left.
@Sushmita maam I think that order of evaluation of function arguments is undefined since when a function is called with arguments, there isn't any sequence point defined since the comma in between the arguments acts as a separator and not an operator. Why is there so much confusion regarding this?
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,833 questions
57,750 answers
108,161 users