Logo 
Search:

C Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C ProgrammingRSS Feeds

C programming practical question 116

  Shared By: Adah Miller    Date: Jan 24    Category: C Programming    Views: 67

Answer:

What is the output for the program given below

typedef enum errorType{warning, error, exception,}error;
main()
{
error g1;
g1=1;
printf("%d",g1);
}


Answer
Compiler error: Multiple declaration for error


Explanation
The name error is used in the two meanings. One means that it is a enumerator constant with value 1. The another use is that it is a type name (due to typedef) for enum errorType. Given a situation the compiler cannot distinguish the meaning of error to know in what sense the error is used:
error g1;
g1=error;
// which error it refers in each case?
When the compiler can distinguish between usages then it will not issue error (in pure technical terms, names can only be overloaded in different namespaces).
Note: the extra comma in the declaration,
enum errorType{warning, error, exception,}
is not an error. An extra comma is valid and is provided just for programmer’s convenience

Share: 
 

Didn't find what you were looking for? Find more on C programming practical question 116 Or get search suggestion and latest updates.


Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: