Data type `long` in C programming -


what difference between long int numberofpoints = 131071100; , long int numberofpoints = 131071100l;

and assignment such int numberofpoints = 131071100l; legal? , if difference between , previous two?

the type of unsuffixed integer constant 131071100 first of int, long int, , long long int in value can represented. value of 131071100 always mathematically correct; type varies (and since long int @ least 32 bits, it's either int or long int).

with l suffix, it's of type long int or long long int; again, value correct -- , happens 131071100l of type long int.

it's valid initialize object of arithmetic type expression of different numeric type. value implicitly converted target type. , in case, since target type long int, there no risk of overflow.

for particular case, only difference between

long int numberofpoints = 131071100; 

and

long int numberofpoints = 131071100l; 

is latter more explicit; meaning same.

the l suffix still needed if expression more complicated single constant. example, if write:

long int foo = 1024 * 1024 * 1024; 

then each constant 1024 of type int -- , entire expression. if int happens 16 bits, multiplication overflow, though mathematical result fit in long int. (the type of literal adjusted depending on value; type of large expression not.) avoid problem, can write:

long int foo = 1024l * 1024l * 1024l; 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -