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;
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.
Ravi said:
1 decade ago
Give some expalnation please.
Suchi said:
1 decade ago
Someone explain briefly.
Raji said:
1 decade ago
Can't understand.
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
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
Ramya dara said:
1 decade ago
Can any one give best example for this ?
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!
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!
Shivani said:
1 decade ago
Can anyone tell me what is enum error?
Praveen Gowda PK said:
8 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.
Sharmi said:
8 years ago
Give explanation for this.
Nagu said:
8 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.
(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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers