Question from quiz

Hi guys. While I was passing the quiz I stuck on some (perhaps silly) question. After that quiz I searched for the answer, but didn't find it.
Here is the code:

1
2
3
4
5
int checkVal(int inVal)
{
    if (inVal)
        return (1);
}

There were 5 options:
1. incorrect return type
2. phantom return value
3. accidental assignment
4. uninitialized local variable
5. malformed function declaration

I will appreciate very much if someone helps me. Thanks.
First of all, state, what is your opinion on each point and try to explain why do you think so. Maybe you do not even need help after all. After that we can correct you and guide you the right way.
Hmm...funny, after your answer I've got it. It's the last one about malformed function declaration.
This function always has to return value. With this definition in case the argument is zero function won't know what to return.
2.phantom return value , which means that if inVal is equals to 0 then no return value .
It's the last one about malformed function declaration.
The question asked about function declaration. This line: int checkVal(int inVal). THere is nothing wrong with it.
Other are obviously not true: there are no local variables, there are no assigments and literal 1 can be used to initialize return type of int.
Your function, however does not return value on all path. If condition if (inVal) is not true, execution will skip return statement and function ends without returning a value which is illegal.
Any properly configured compiler will warn in this simple case: http://goo.gl/QCPoHb

Thanks a lot!
Topic archived. No new replies allowed.