User-Defined Data Type In C Language.

User-Defined Data Type In C Language.

c programming language

Hello Programmer,

The previous blog we studied about derived data type and also studied about there 4 types but today we will study about user-defined data type in a c programming language.


As name defined that user-defined data type is those data type which is defined by the user according to their needs.

In user-defined use set data type name and set which type of value it takes from the user in runtime.

There are two types of user-defined data types:

A) typedef data type.

B) enum data type.


Now we will discuss each type one by one.

A) typedef data type:

In c programming language programmer has power or rights to define new data type which is equivalent to the existing data type with the help of typedef statement.

Example:     typedef int integer;
                        
                    integer a,b;

In the above example define an integer as a data type synonymous to int type and then integer can be used to declare a variable as you have seen above example.

int a,b = integer a,b;

Both statements are true and they are same.

As you see typedef just create a new name for an existing type, it does not create a new type. typedef makes the program easy to read and understand.



B) enum data type:

In c programming language enum is another user-defined data type.

Syntax:    enum length
                {
                    value-1,value-2,......,value-n;
                  };

where length is the name of the enumerated data type and the value inside the curly braces are values that variable of type length can take.


example:
                        enum fruit
                        {
                                apple,mango,banana,orange;
                        };

Now any variable of type fruit can take any of the five values namely apple, mango, banana etc but no other values.

The variable of enum data type fruit can be defined as fruit x,y;

 

Sharing Is Caring...       

Comments :

Post a Comment