what kind of datatype should i use for this 600851475143 in c++?
i'm using c++, even 开发者_如何学编程if i declare long int, there is error like......
long int num = 600851475143;
warning: integer constant is too large for ‘long’ type
which datatype should be used in this case?
You have to put the suffix L after the number:
long long int num = 600851475143LL;
A lot of it depends on the platform and compiler you are using.
If you are on a x64 platform, a long datatype in C++ should work. A signed long ranges from −9,223,372,036,854,775,808 to +9,223,372,036,854,775,807. An unsigned long on the other hand ranges from 0 to +18,446,744,073,709,551,615.
Also depending on the compiler and platform there are a few other datatypes which effectively is the same thing (doubleword, longword, long long, quad, quadword, int64).
C (not C++) supports the long long data type. Say if you are on Fedora 10 x32 then gcc 4.3.0 supports the long long datatype but you must put the LL after the large literal. See http://www.daniweb.com/forums/thread162930-2.html
You should distinguish type of variable from type of integer expression you use as value being assigned to variable. As tur1ng specified, you are supposed to use integer literal suffix to precise type of value you assign if ambiguity may occur.
Unsuffixed decimal value can have different type: int
, long int
, unsigned long int
, long long int
, so it's a good idea to be explicit.
you just have to do as follows (if you are using java):
long num = 60085147514L;
this declares it as "long" data type which allows you to store longer numbers
精彩评论