#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 ? | 53 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 |
how to swap two numbers in a linked list without exchanging the data but only the links?
Who created stl?
Do you like to Submit Questions in Bulk under Same Category?? Then use our Bulk ListerDo you like to Submit Questions in Bulk under Same Category?? Then use our Bulk Lister
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
WHAT IS THE DIFFERENCE BETWEEN C++ AND VC++
draw a flowchart that accepts two numbers and checks if the first is divisible by the second.
Find the error in the following program struct point {struct point *next; int data; } x; main() {int...data; } x; main() {int i; for(x=p;x!=0;) x=x->next,x++; freelist(x); } freelist(x) {free(x); return }
Give the output of the following program main() {char *p='a'; int *i=100/*p; } what will be the value of *i= 1
In what cases using of a 'template' is a better approach then using of a 'base class'?
6 Answers Lucent, Mind Tree, Wipro,
#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?
why does the execution of a c++ program start with main()???
What is stl stand for?