-
exponential operator
I am having problems with precedence. I am looking at a study guide and it says that:
2^4/2*3
is equal to 4 (where ^ is the exponential operator). And also,
4^3/2/3/2
is equal to 4 (where ^ is the exponential operator).
I can't see how they get 4 and also I can't find any information on the exponential operator (putting it into search engines and in my book). I think it may have something to do with the numbers being of type int so that when you divide two ints and get a decimal value, it rounds down.
I don't know if I am right and I can't see how they get 4 four the answer to both of these expressions. Help me or at least let me know where I can read about the exponential operator
-
there isn't a '^' exponential operator in C++, but there is an '^' as the XOR operator. SInce XOR has lower precendence than * and /, XOR is evaluated last. So the equation:
2^4/2*3 == 2^((4/2)*3) when considering precedence.
which simplifies to
2 ^ 6, which equals 4
Same thing for the next equation
4 ^ 3/2/3/2 = 4^0 = 4
-
#include <math.h>
use the pow function it returns a double;
double pow(double base, double exp);
double ans = 0.0;
2^4/2*3 //try this ans = pow(2,4)/2*3;
is equal to 4 (where ^ is the exponential operator). And also,
4^3/2/3/2 //try this ans = pow(4,3)/2/3/2;