Hi,

I have been trying to figure this out and I know it must be something simple but I cant get it. Why does the following code give an answer of 1.

double a=8;
cout<<pow(a,1/3);

I would think it should be 2.
Thanks

1/3 is integer division which results in 0. Try 1.0/3.0 to get float division.

Thanks, i forgot about that :) .It gets truncated.
Thanks once again.

Thanks, i forgot about that :) .It gets truncated.
Thanks once again.

Just to clarify (words mean things)

What you've got is the result of integer division.

Truncation is what happens when you assign a floating point value that has a fractional part to an integer variable, or typecast the floating point to an integer type.

Thanks, Thats absolutely right.

Just to clarify (words mean things)

What you've got is the result of integer division.

Truncation is what happens when you assign a floating point value that has a fractional part to an integer variable, or typecast the floating point to an integer type.