Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the data type returned for the following function?

int func()
    {
        return (double)(char)5.0;
    }

 

  • A.char
  • B.int
  • C.double
  • D.multiple type-casting in return is illegal

Answer: B

Correct answer: int

The declared return type wins. Whatever casting happens inside, the value is converted to the function’s return type on the way out - so func returns an int. Here 5.0 becomes a char, then a double, and finally an int at the return.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.