How to use exponents?

So I tried this:

[code]#include <stdio.h>

int main(int argc, const char * argv[])
int number = 5;
printf(""%d" squared is “%d”.\n", number, number^2);

return 0;


But I get this:

[quote]“5” squared is “7”.
Program ended with exit code: 0[/quote]

I thought that ^ was how to get an exponent, as in number*number? Not sure where 7 came from.

Any help?


^’ is the bitwise-XOR operator; that’s why you got 7 for 5^2 (=(101 ^ 010) = (111)).

To get its square, multiply a number by itself once.

int num;

The square of num: num * num; //

for example:
num = 5;
num * num // is equal to 5^2 or 5x5, that is equal to 25.