mathematical power operator not working as expected

c, math

Solution

`^` is not the mathematical power operator in C, it's the bitwise exclusive-OR operator. You probably want the pow function, which takes two doubles.

Problem

``` short sho1, sho2; printf("Enter two shorts.\n"); scanf("%hd %hd", &sho1, &sho2); printf("%hd^%hd is %hd.\n", sho1, sho2, sho1^sho2); ``` When I enter '2 2', I get this output: 2^2 is 0. How come? I'm using the MinGW GCC compiler in Eclipse, in case that's of any importance.

Original source