Returning long int from short int function?

I discovered a question in the review page, I have to write any function that takes in 3 int guidelines and return long int

Recommendations what the item says
// Produce the purpose subtract() in which accepts some int guidelines, and
// returns a lengthy int.The purpose will subtract the 2nd two arguments
// on the first debate, and return the actual result.

Learn how to convert by short int that will long int

You may either placed the int to a long int or you’ll be able to let the particular compiler get it done for a person (by how, “int” and “short int” have not meant exactly the same thing since 1985).
//explicitly turn all the arguments to a long.
//in truth, you just have to have to turn the initial one with a long
//and the remainder will often be switched automatically
lengthy castResult = (long)int1 — (long)int2 — (long)int3;

//You may just accomplish the subtraction and also store
//it within a long.the problem with this is if int1 — int2 :int3 < -232
//in of which case, you get the drastically wrong answer with this one.
lengthy implicitCast = int1 — int2 — int3;

Leave a Reply