0

I was trying the following code

printf("%d", 010 % 10);

I was expecting it output be 0, but it is 8.

Why? Is there any way to get the last digit of an integer which is taken as input.

Brijesh Joshi
  • 19
  • 1
  • 10

1 Answers1

5

Any numeric literal in c or c++ starting with a zero will be interpreted as octal

So your calculation is 8 modulo 10, which is 8