edited by
601 views

1 Answer

2 votes
2 votes
#define cube(x) x*x*x 
main(){ 
int a=3,b; 
b=cube(a++); 
printf("%d %d",a,b); 
}

cube(3++) 

a++ * a++ * a++

++ (postfix) has higher precedence and associativity is left to right

(a++) * (a++) * (a++)

first leftmost a++ is calculated but non-modified value will be returned. So now a = 4 but 3 is returned

3 * (a++) * (a++)

now second a++ is calculated but non-modified value will be returned. So now a = 5 but 4 is returned

3 * 4 * (a++)

last a++ is calculated but non-modified value will be returned. So now a = 6 but 5 is returned

$3 * 4 * 5 = 60$

so b = 60 and a = 6

Output : $6 \ 60$

Edit : As Shaik mentioned in comments a++ * a++ * a++ is undefined. So order of execution of all 3 (a++) is not defined. Still answer won't change and will be 6 60. Answer is Undefined Behavior if there is an option "Undefined Behavior ".

edited by

Related questions

1 votes
1 votes
1 answer
1
pooja kadu asked Aug 7, 2016
2,214 views
consider the declaration:char first(int(*)(char,float));int second(char,float);Which of the following function invocation is valid and how?a) first(*second);b) first(&sec...
0 votes
0 votes
0 answers
2
2 votes
2 votes
1 answer
3
anonymous asked Apr 16, 2017
3,248 views
4. Which of the following is not a valid variable name declaration and why?a) float PI = 3.14;b) double PI = 3.14;c) int PI = 3.14;d) #define PI 3.14
0 votes
0 votes
2 answers
4
saurabh111 asked Sep 8, 2018
303 views
what is binding in c ??