Aptitude (12) ASP.NET (2) Automata (4) Browser (1) C (5) C# (1) C++ (10) Code (3) CSS (1) Data Structure (1) DATABASE (3) HTML (1) java (43) JSP (1) math (1) MySql (8) other (6) php (3) Servlet (3)

Friday, 27 January 2012

User defined type


User defined type is a way from which help an user can create variables of own type.
There is two way  for creating user defind data type:
1.       Using typedef  keword
2.       Using enum keyword(enumerated data type).
1.typedef----
       typedef existing_data_type new_userdefined_type;

e.g
typedef int krish;

krish a,b,c;/* a,b,c are integer variable*/
we can further use keyword typedef to create new data type from datatype being used as:
 typedef krish kg;
kg l,m;  /* l,m are integer variable*?/

typedef with structures:

typedef struct class
{
……..
……..
} my;


function()
{
class  var1,var2; /*simple object declaration*/
my var3;        /*declaration using dublicate datatype i.e user type*/
}

2.Enumerated datatype:
Enum cricket(sachin,rahul,shehbag,…..,dhoni);
cricket a,b,c;
a=sachin;  /*valid*/
b=10;  /*invalid*/
c=jaysurya;  /*invalid*/



No comments:

Post a Comment