user2080499
user2080499

Reputation:

Why do integers starting with 0 print out weirdly?

I'm writing a function in C (using Eclipse) which has a integer called alpha, and its assigned value is 077.

But when I print it out, it prints 63 instead of 77 or 077.

In fact, it's not just 077 but any integer with a leading 0 is printing an unexpected value. When I remove 0 from 077, it does print the correct value 77.

What effect does this leading 0 have?

Upvotes: 2

Views: 131

Answers (1)

ouah
ouah

Reputation: 145919

A number starting with a 0 is an octal number.

077 is 7 x 8 + 7 == 63

Upvotes: 13

Related Questions