C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - Point Out Errors (Q.No. 4)
4.
Which of the following is correct about err used in the declaration given below?
 typedef enum error { warning, test, exception } err;
It is a typedef for enum error.
It is a variable of type enum error.
The statement is erroneous.
It is a structure.
Answer: Option
Explanation:

A typedef gives a new name to an existing data type.
So err is a new name for enum error.

Discussion:
12 comments Page 1 of 2.

Deepa said:   4 years ago
Please give an example.

Nikhil said:   5 years ago
typedef is used to give a name for the already named variable for example.

typedef int BoyAge; // if every time in the code, I can't type BoyAge is a lengthy process so I can give a nickname to that variable.

BoyAge b;

I hope everyone understand this.

Nagu said:   5 years ago
Enum is keyword like structure keyword.

(example)
you creat structure this way
struct (structure name)
{
(structure member or element)
} ;
same way using enum
(example)
enum (enum name)
{
(enum member or element)
};

So enum is keyword and error is enum name.

Sharmi said:   6 years ago
Give explanation for this.

Praveen Gowda PK said:   6 years ago
The typedef is a keyword in the C and C++ programming languages. The purpose of typedef is to assign alternative names to existing types, most often those whose standard declaration is cumbersome, potentially confusing, or likely to vary from one implementation to another.

Shivani said:   9 years ago
Can anyone tell me what is enum error?

Kishore said:   1 decade ago
C provides a facility called typedef for creating new data type names. For example, the declaration

typedef int Length;

makes the name Length a synonym for int. The type Length can be used in declarations, casts, etc., in exactly the same ways that the int type can be:

Length len, maxlen;
Length *lengths[];

Similarly, the declaration

typedef char *String;

makes String a synonym for char * or character pointer, which may then be used in declarations and casts:

String p, lineptr[MAXLINES], alloc(int);
int strcmp(String, String);
p = (String) malloc(100);

Notice that the type being declared in a typedef appears in the position of a variable name, not right after the word typedef. Syntactically, typedef is like the storage classes extern, static, etc. We have used capitalized names for typedefs, to make them stand out.

Hope you got it!

Ramya dara said:   1 decade ago
Can any one give best example for this ?

Priya (smart) said:   1 decade ago
typedef void DRAWF( int, int );
This example provides the type DRAWF for a function returning no value and taking two int arguments. This means, for example, that the declaration

DRAWF box;
is equivalent to the declaration

Raji said:   1 decade ago
Can't understand.


Post your comments here:

Your comments will be displayed after verification.