About the LONG data type

Why the following is illegal
long number = 234567890*10;
while the following is legal??
long number = 2345678900;
helloyipAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
jkrConnect With a Mentor Commented:
The highest value for a signed long is 2^32 ==  2147483648;
By assigning 'number = 2345678900', (which is the same as 'number = 0x8BD03834'), 'number' has the actual value '-1949288396', whilst multiplying '234567890*10' would cause a signed long overflow.
0
 
helloyipAuthor Commented:
tks a lot!!!
0
 
jkrCommented:
Ooops: BTW - what compiler are you using? It should at least issue a warning...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.