#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 ? | 55 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 ? | 32 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 |
Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.
Write a program in C/C++ to implement reader- writer problem
What is the Difference between CArray and CList?
1 Answers ProdEx Technologies, Siemens,
What are stl algorithms?
write a c++ to define a class box with length,breadth and height as data member and input value(),printvalue() and volume() as member functions.
What are the components of stl?
sir please send me bpcl previous question papers
0 Answers BPCL Bharat Petroleum,
wap in c++ which accept a integer array and its size as argument and replaces element having even values with its half and element having odd values with twice its value
Who created stl?
Can we use stl in coding interviews?
Assume I have a linked list contains all of the alphabets from "A" to "Z?" I want to find the letter "Q" in the list, how does you perform the search to find the "Q?"
what is electronic software