Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
C++
int main( )
{
	long int zip; // Zip code
zip = 02137l; // Use the Zip code for Cambridge MA

std::cout << "New York's Zip code is: " << zip << '\n';
getch();
return(0);
}

&&
C++
int main( )
{
	long int zip; // Zip code
zip = 2137l; // Use the Zip code for Cambridge MA

std::cout << "New York's Zip code is: " << zip << '\n';
getch();
return(0);
}

why the value ZIP is change ???
Posted
Updated 15-May-12 9:16am
v2
Comments
Sandeep Mewara 15-May-12 15:18pm    
P.S.: Just formatted the code part and completed the title.

You trying to ask what is the difference if you define zip as '21371' & '021371'. Right?
Anderso0on 15-May-12 15:20pm    
yes

1 solution

Octal.

In C++ numbers beginning with zero are taken as Octal (base 8), rather than Decimal, (base 10) (unless the zero has an "x" after it, in which case it is Hex (base 16)).

[edit]Forgot a ")" and two upper case letters... - OriginalGriff[/edit]
 
Share this answer
 
v2
Comments
Anderso0on 15-May-12 15:27pm    
i do not understand you
lewax00 15-May-12 16:10pm    
It's a different number system, that only uses the digits 0-7. Check the Wikipedia article for more: http://en.wikipedia.org/wiki/Octal
OriginalGriff 16-May-12 1:48am    
We humans work in Base 10 - probably because we have ten digits on our hands so it becomes a "natural" number system to work with. But it's not the only way you can work with numbers! Decimal (another name for Base 10) uses the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9, then moves to Tens, then Hundreds, the thousands. But you could just use 0, 1, 2, 3, 4, 5, 6 and 7 - then move to Tens, and then hundreds. This is called Octal, or Base 8 and it has some advantages in computing over Base ten - it fits neatly in with the binary that computers actually use because each digit is made of three binary digits, where Decimal does not - it needs three-and-a-bit digits which is hard to represent. Wiki will help explain it better than I can: http://en.wikipedia.org/wiki/Octal

But any number in C++ that starts with a 0 is in Octal, if it doesn't, it's Decimal.
Chuck O'Toole 15-May-12 16:48pm    
A quick thing for you to check. What's the difference between "15" and "0x15"? Hint, it's the "number base" (decimal - base 10, hexidecimal - base 16). "015" is yet another "base" (octal, base 8). Each represents a completely different value and will show differently when printed out as an integer with "cout" (base 10).
Maciej Los 15-May-12 15:33pm    
+5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900