Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


#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



#define CUBE(x) (x*x*x) main() { int a,b=3; a=cube(b++); printf("%d %d",a,b); } Wh..

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

#define CUBE(x) (x*x*x) main() { int a,b=3; a=cube(b++); printf("%d %d",a,b); } Wh..

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

#define CUBE(x) (x*x*x) main() { int a,b=3; a=cube(b++); printf("%d %d",a,b); } Wh..

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

#define CUBE(x) (x*x*x) main() { int a,b=3; a=cube(b++); printf("%d %d",a,b); } Wh..

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

#define CUBE(x) (x*x*x) main() { int a,b=3; a=cube(b++); printf("%d %d",a,b); } Wh..

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

#define CUBE(x) (x*x*x) main() { int a,b=3; a=cube(b++); printf("%d %d",a,b); } Wh..

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

#define CUBE(x) (x*x*x) main() { int a,b=3; a=cube(b++); printf("%d %d",a,b); } Wh..

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

#define CUBE(x) (x*x*x) main() { int a,b=3; a=cube(b++); printf("%d %d",a,b); } Wh..

Answer / karthik p b

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

#define CUBE(x) (x*x*x) main() { int a,b=3; a=cube(b++); printf("%d %d",a,b); } Wh..

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

#define CUBE(x) (x*x*x) main() { int a,b=3; a=cube(b++); printf("%d %d",a,b); } Wh..

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

Post New Answer

More STL Interview Questions

write a program that input four digit no and finds it is palindrome or not

2 Answers  


When did c++ add stl?

0 Answers  


What is a standard template library (stl)?

0 Answers  


#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?

12 Answers   Wipro,


Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.

0 Answers  


a program using one dimensional array that searches a number if it is found on the list of given input numbers given by the user and locate its exact location in the list.

0 Answers  


how to use C++?

0 Answers   NIIT,


What is stl in c++ with example?

0 Answers  


How do you convert stl to steps?

0 Answers  


how to swap two numbers in a linked list without exchanging the data but only the links?

3 Answers   Wipro,


Describe the My Computer and My Documents folders; identify the elements that are present in every Window.

0 Answers  


How connect plc and pc through software

0 Answers  


Categories