Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How do you make the compiler check if the result of an operation is an integer?

+2 votes
asked Aug 14, 2020 by Logan Wright (150 points)
edited Aug 15, 2020 by Logan Wright
q says it all.

2 Answers

0 votes
answered Aug 15, 2020 by Peter Minarik (88,520 points)

I think you're asking the question in relation to Java.

In Java and many other strongly typed languages (just to name a few: C/C++, C#), a function can only return with one type of an object.

ReturnType Function(ArgumentType1 argument1, ArgumentType2 argument2, ...);

So when you defined your function, may it return void (nothing) or built-in types, or a user-defined type, it only can return that type. So the compiler can check if the variable that takes the value of this method is compatible to store something that is returned by the method.

You do not make the compiler check for integral type. Instead, you look at the return value of the function and check if it is indeed an integral type.

0 votes
answered Aug 22, 2020 by John Smith (140 points)

Confused about the question, context maybe?

a string representation of a number "12345" instead of 12345?

    isInteger(val)

            for each character in val

                     if character is not digit

                             return false

            return true

non-typed language such as JS isInteger()

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...