0
#include<bits/stdc++.h>
using namespace std;

int fun()
{
  int d = 0012;

  return d;
}

int main()
{
  cout << fun() << "\n";

  return 0;
}

Output : 10

here in fun() function d value is 12 but when called fun() and print it value, it is 10 why fun() function return 10?

tstanisl
  • 13,520
  • 2
  • 25
  • 40

1 Answers1

4

because 1*8+2 = 10.

You starts your number with 0, which means, it is octal.

The Backus Naur form is so:

ISO/IEC 9899:TC2
6.4.4  Constants
Syntax
integer-constant:
  decimal-constant integer-suffixopt
  octal-constant integer-suffixopt
  hexadecimal-constant integer-suffixopt
octal-constant:
  0
  octal-constant octal-digit
octal-digit: one of
  0 1 2 3 4 5 6 7
alinsoar
  • 15,386
  • 4
  • 57
  • 74