1

I'm using Visual Studio 2008 Express. If I debug this program, the variable num holds the value 322, even when it's initialized to 0502. What am I missing here?

int main()
{
    int32_t num = 0502;

    return 0;
}

int32_t is defined in the portable version of pstdint.h Version 0.1.12 as

typedef signed long int32_t;
damian
  • 79
  • 8
  • @rubenvb It's not a duplicate - that question is a hint (if you don't know what octal digits are.) – David Jun 14 '13 at 13:07

2 Answers2

7

0502 is octal, since it has prefix 0. 502 in octal is 322 in decimal.

ForEveR
  • 55,233
  • 2
  • 119
  • 133
  • Right. Thanks. After 10 years of programming, this is the first time I come across the notion of octals. – damian Jun 14 '13 at 05:37
  • I just found this entry about the history of octals and it's use nowdays. Very interesting. http://programmers.stackexchange.com/questions/98692/where-are-octals-useful – damian Jun 14 '13 at 05:48
3

If you start a integer value with 0 it is considered as an octal number, similarly 0x is used for hex.

Asha
  • 11,002
  • 6
  • 44
  • 66