OOPS - [C++ User-Defined Data-Types]

♠ Posted by Unknown in at 09:56

User-Defined Data Types


C++ supports a feature known as “type definition” that allows users to define an identifier that would represent an existing data type.  The user-defined data type identifier can later be used to declare variables.  It takes the general form.

Syntax:
                                                typedef  <type>  <identifier> ;

Example:
                                                typedef  int units ;
                                                typedef float marks ;

here, units symbolizes int and marks symbolizes float.  They can be later used to declare variables as follows.

                                                units  batch1, batch2;
                                                marks name[150], name[150] ;

Another user-defined data type is enumerated data type provided by ANSI standard.  It is defined as follows.

Syntax:
                                                enum  <identifer>  {value1,  value2,…………, valuen};

Example:
                                                enum  day {Monday, Tuesday,…….,Sunday};
                                                enum  day  week_st,  week_end;

0 comments:

Post a Comment