1 votes 1 votes #include<stdio.h> #define ADD(a,b)(a+b) #define SQUARE(x)(x*x) int main() { int x=2; int y=3; int z = ADD(SQUARE(x++),y); printf("%d\n",z); return 0; } What is the output of the above code snippet? Programming in C ace-test-series + – Ayush_Pal asked Apr 26 Ayush_Pal 154 views answer comment Share Follow See all 4 Comments See all 4 4 Comments reply ꧁༒☬ĿọŗԀ 🆂🅷🅸🆅🅰☬༒꧂ commented Apr 27 reply Follow Share is ans 7 ? 0 votes 0 votes Ayush_Pal commented Apr 27 reply Follow Share answer is 9 0 votes 0 votes Shaik Masthan commented Apr 27 reply Follow Share #define is a preprocessor statement. Square(x++) is replaced with (x++ * x++) - updating one variable morethan once before one sequence point -- undefined behavior in C. 2 votes 2 votes ꧁༒☬ĿọŗԀ 🆂🅷🅸🆅🅰☬༒꧂ commented Apr 27 reply Follow Share ah got it . square (x) will be treated as x++ * x++ so it will give 6 and after add it with it y it will give 9. bt as it is not acceptable in C so it will be undefined behavior. 1 votes 1 votes Please log in or register to add a comment.
1 votes 1 votes 9 This question is easy the only catch is in int z = ADD(SQUARE(x++),y); in this line .Firstly it will take the value of 2 as it is and then increment so the value will be 2*3.z=(2*3)+3 = 9. Abha Gupta answered Apr 29 Abha Gupta comment Share Follow See 1 comment See all 1 1 comment reply ꧁༒☬ĿọŗԀ 🆂🅷🅸🆅🅰☬༒꧂ commented Apr 29 reply Follow Share @Abha Gupta @pinaksh10 see shaikh mastan sir's comment ur flow of execution is correct , bt it will undefined behaviour. 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes #include<stdio.h>#define ADD(a,b)(a+b)#define SQUARE(x)(x*x)int main(){int x=2;int y=3;int z = ADD(SQUARE(x++),y); // here is the cache which is 1st time Square takes 2 and 2nd time give 3 means SQUARE(old x*updated x)= SQUARE(2*3) gives 6 then add(6+3)=9printf("%d\n",z);return 0;}So the answer is 9 pinaksh10 answered Apr 27 pinaksh10 comment Share Follow See all 0 reply Please log in or register to add a comment.