#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 ? | 51 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 |
What is a standard template library (stl)? What are the various types of stl containers?
Write a program in C++ to concatenate two strings into third string using pointers
How connect plc and pc through software
differentiate between private, public and protected data members of the class using example.
Is stl part of c++ standard?
What is stl stand for?
Explain how to insert a hyperlink in to an Excel worksheet and save a Word document as a Web page.
Is string part of stl?
WHAT IS THE DIFFERENCE BETWEEN C++ AND VC++
What is the underlying datastructure of map?
#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?
What is the name of your birth place?