Concept of Octal literal in C
One day while debugging one code i got one interesting things ..let me explain you by bellow’s example.
#include<stdio.h> main() { int a=010; printf("a is %d",a); }
if you think output of this program will
“a is 10″
then your are missing something….
the real output of this program is
“a is 8″
REASON :
Actually in c and c ++ language 0 (zero) is the octel literal so when you wrie
a = 010 ;
then its Octel representation of 8.
Any integer value starting with ’0′ is an octal value. I.e.: 01 is octal 1, 010 is octal 10, which is decimal 8, and 0 is octal 0 (which is decimal, and any other, 0).
As per the C++ Standard:
2.14.2 Integer literals [lex.icon]
integer-literal:
decimal-literal integer-suffixopt
octal-literal integer-suffixopt
hexadecimal-literal integer-suffixopt
decimal-literal:
nonzero-digit
decimal-literal digit
octal-literal:
0
octal-literal octal-digit
You may like to read this also....
Post comment
Search in this website
our sponsors
latest comments
- shinto peter on How to configure mail from localhost ( wamp ) using PHP?
- tammylleanne on Implementation limitation of c programming language
- Deepak on How to access/unblock songs.pk in india?
- Deepak on How to access/unblock songs.pk in india?
- prk on How to access/unblock songs.pk in india?
Find us on Facebook
Top Authors
Find us on stackoverflow
Polls
Loading ...
My Bookmarks
- Audio/video Recorder & player application based on MATLAB
- check dependency of your binary
- defination of all standard c programming language function
- Great Question-Answer on c programming
- know what your c code means
- Limition of c programming language
- List of all version of c programming language
- Online c compiler
- php freelancing work
- some more stuff on C programming language
- Volatile Keyword in Embedded System
- Write Android application in c language