Can a long int be returned by a function in c?

Suppose we want to return a long integer by a function. How to do it? It's really?

long int function()
{
  long int b;
  b=1000000000;
  return b;
} 

      

+3


source to share


4 answers


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.

+10


source


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.

+2


source


A function can return almost any type:

6.9.1

The return type of the function must be an invalid or complete object type other than an array type.

What is it.

+2


source


Can a long int be returned by a function in c?

Can long int be returned by a function in c?

         

+2


source







All Articles