Slideshow

Monday 25 February 2013


How does an enumstatement differ from a typedef statement? 

Ans:
Typedef statement allows user to define an identifier that would represent an
exiting data type. The user-defined data type identifier can be used further to
declare variables. It has the following syntax
typedef datatype identifier;
where datatype refers to exiting data type and identifier is the new name given to
this datatype. For example
typedef int nos;
nos here symbolizes int type and now it can be used later to declare variables like
nos num1,num2,num3;
enum statement is used to declare variables that can have one of the values
enclosed within braces known as enumeration constant. After declaring this, we can
declare variables to be of this ‘new’ type. It has the following syntax
enum identifier {value1, value2, value3……,valuen);
where value1, value2 etc are values of the identifier. For example
enum day { Monday, Tuesday, Wednesday, Thursday, Friday,
Saturday}
We can define later
enum day working_day;
working_day=Monday;
The compiler automatically assigns integer digits beginning with 0 to all
enumeration constants.

No comments:

Post a Comment