Can a long int be returned by a function in c?
Yes, it really is.
As long as you tweak the correct value long int
(which we see, you do # ) and intercept this in another long int
(you need to take care), it should be fine.
#) According to the standard, C11
LONG_MAX
less +2147483647
and 1000000000
less. Chapter §5.2.4.2.1 for reference.
source to share
The C standard provides for a minimum size of 32 bits for long int
, stored in such a way as to ensure that values in the range [-2147483647, +2147483647] can be represented. (Note that the 2 compliment presentation gives you -2147483648). Thus, the destination of 1,000,000,000 is long int
always determined.
The returned copy of the value is also correctly defined long int
.
Note that if you did not initialize b
(i.e. if you omitted the operator b=1000000000;
) then the behavior of your program would be undefined.
source to share