#define CUBE(x) (x*x*x)
main()
{ int a,b=3;
a=cube(b++);
printf("%d %d",a,b);
}
What should be the value of a and b? My calc a=4 but syst
a=6 how pls tell me if you know it?
Answers were Sorted based on User's Feedback
Answer / maitri
Couple of things:
a. macro is expanded as (x++ * x++ * x++)
b. what we have here is a postfix operator
so a = CUBE(3)=3*3*3
and b = 6 (incremented thrice)
Is This Answer Correct ? | 52 Yes | 14 No |
Answer / vasanth
since macro is expanded like (x++ * x++ * x++) = (3 * 4 *
5) => a = 60
and final value of b = 5++ => 6
ans : 60, 6
Is This Answer Correct ? | 31 Yes | 15 No |
Answer / pratap keshari
The output will be 27 6
b++ will be replaced as 3++ in the macro and these values
will be evaluated after the macro execution.Hence first it
will evaluate to 3's cube and then increment 3 three times
Is This Answer Correct ? | 10 Yes | 7 No |
Answer / p. smith
27 4 is the output.
the call to the macro sets a = b*b*b with b = 3, 3 cubed is 27
then b is incremented to 4 after the macro call
Is This Answer Correct ? | 22 Yes | 21 No |
Answer / riadh khedhiri
the output on a my box:
Linux 2.6.32-22-generic-pae #36-Ubuntu SMP Thu Jun 3 23:14:23 UTC 2010 i686 GNU/Linux with gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
a = 27
b = 6
Is This Answer Correct ? | 4 Yes | 4 No |
Answer / prabhaaa
since macro is expanded like (x++ * x++ * x++) = (3 * 4 *
5) ..here the value increments in each of its position. first [3 *3++*(3++)++] = [3*4*4++]
= [3*4*5]
a = 60
and here b increments three times .3++=4, 4++=5 ,5++=6.
final value of b = 5++ => 6
ans : 60, 6
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / ashwini
above code have error.If used CUBE instead of cube then
output will be
A = CUBE(B++ * B++ * B++)
as ++ is post increment plus operator so A = 27 and then B
gets incremented three times so B = 6
Is This Answer Correct ? | 3 Yes | 4 No |
a will be 27 and b will be 6.
since the cube root of 3 is assigned to 'a' it will contain the value 27, and after this 'b' will gets incremented 3 times (x++ * x++ * x++) hence 'b' will become 6
so a = 27 b= 6
Is This Answer Correct ? | 2 Yes | 3 No |
Answer / alan
it depends on the compiler
(x++ * x++ * x++) ==>correct.
the question is when x++?
Note the second time x++, it use the value of x or x++ of
the first x++?
Is This Answer Correct ? | 2 Yes | 4 No |
Answer / jayprakash singh
in question we use #define CUBE(X) (X*X*X) but in main
function we use a=cube(b++);
what is this i think it is wrong it must be error at
compile time.
if we use a=CUBE(b++); instead of a=cube(b++);then output
will be 27 6
becuse 1st (3*3*3)=27 then increment of value b thrice so b=6
Is This Answer Correct ? | 1 Yes | 5 No |
Distinguish between: a) Normal layout & Print Layout views b) Windows Clipboard & office Clipboard c) Save & Save As Commands d) Program File & Data File e) Pie Charts & Barr Charts
write a program that input four digit number and find how many 7 that number contains
how to overload << and >> operator in c++
How the STL's are implemented, What the difference between templates and STL?
What is the name of your birth place?
How Find, Replace and Go To commands ca be used to substitute one character string for another? Explain with the heIp of an example.
if 4-5 year old brother is standing on d roof with me and watching d moon, suddenly moon coverd by cloud then how will i explain d hiding of moon to my brother.
what is strcture i++ i ++i answer to this i=5 what is the out put
write a piece of c++ code which allocate memory to the 50 object of type CObj
what are you now programming Languages C+
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.
What two types of containers does the stl provide?