1

This code, when I run it on C++ Borland compiler 5.02

#include<iostream.h>
void main()
{
    int x;
    cin>>x;  
    cout << x;
}

When enter 0010 to x, the output is 8? And these for some entries that have zeroes on its left, but not all?

J. Steen
  • 15,470
  • 15
  • 56
  • 63

1 Answers1

5

In C++:

  • Octal numbers have a leading 0.
  • Hexadecimal numbers have a leading 0x.
  • Otherwise, you have a decimal number.

Therefore:

  • 0x10 is a hexadecimal number representing 16.
  • 010 is an octal number representing 8.
  • 10 is a decimal number representing 10.
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173