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

Discussion

What is the output of code given below?

enum m{JAN, FEB, MAR};
    enum m foo();
    int main()
    {
        enum m i = foo();
        printf("%d\n", i);
    }
    int  foo()
    {
        return JAN;
    }

 

  • A.Compile time error
  • B.Depends on the compiler
  • C.Depends on the standard

Answer: A

Correct answer: Compile time error

The prototype declares enum m foo(); but the definition is written int foo(). The two conflict, and the compiler rejects the program - even though an enumeration is represented as an integer, the declared types must match.

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

Post your comment

Please log in or register to post a comment.