0
#include <stdio.h>

int main (void)
{
  int x = 10^2;
  long a = 4000465006540123; //(16 places)
  long b = 4000465006540123 % x;
  
  printf("%li\n", b);
}

When I ran the code, (it compiled properly), the code printed out '3'. Isn't it supposed to print out '23' instead, as x is 100, not 10?

James Kim
  • 65
  • 1
  • 3
  • 7
    `^` is not the power operator in C. It is bitwise XOR. Do basic debugging. At least print out the values to check. – kaylum Aug 13 '20 at 06:20

1 Answers1

5

int x = 10^2; same int x = 8; as ^ is the exclusive-or operator.

Use int x = 100; or 10*10.


Note: In C, % is the remainder operator than a modulus one. Negative results of a%b occur when a < 0.

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256