Derived Data Type In C Programming.

Derived Data Type In C Programming.


Hello Programmer,

In the last blog, we studied the primitive data type. we studied 5 types of a primitive data type but today we will discuss Derived data type.

Mainly derived data type divide into 4 parts...

1) Array

2) Structure

3) Union

4) Pointer

Now we will explore each data type one by one.



1) Array:  


Firstly we discuss the definition of an array. An array is a set of one type of element is called an array.

In array, you can set only one type of element if you make integer type array you have to set only integer value and if you create string type array you have to set only string. An array is a collection of a homogenous element.


An array is a divide in 2 types:

1) One-Dimensional Array

2) Multi-Dimensional Array

Now we will explore each type of array.

A) Linear Array or One Dimensional Array:

Linear array or One-dimensional array contains only one row or one column. In one dimensional array, each element can be referred by one index.

The indexing of the array starts from zero(0). It means the first element of the array is placed in zero indexes. 

Syntax:- datatype array name
                int student[10];

In the above example, we create an integer array whose name is a student and the student array can have taken only 10 integer value.

example: student[0]=1;
                student[1]=2;
                student[2]=3;
                 student[3]=4;
                    .    
                    .
                    .
                student[9]=10;


In memory element of an array is store in continuous order.


B) Multi-Dimension Array:       


An array in which each element of an array are defined by more than one subscript is known as a multi-dimension array. If the element of the array is referred by two subscripts is a two-dimensional array and if the element of the array is referred by three subscripts is a three-dimensional array and so on.

In c language, there is no limit to the number of dimensions.

The element of the multi-dimension array is store in the form of row and column.
Syntax: int a[5][10];



2) Structure:

The data type used to group a number of data item together to form a single entity is known as structure.

In structure, you can store multiple types of data.

The difference of array and structure is that in an array we can store the only the same type of data but in the structure, we can store multiple types of data.

In c programming language you can declare structure with the struct keyword  

Syntax:      struct user_given_name
                   {
                        int number;
                        char ch;
                        float pi;    
                    };   




3) Union Data Type:


Union data type is similar to structure data type except that it has the union keyword instead of struct and the main difference of union and structure is in term of storage. 

In structure, each element of structure has a different storage location but in union element, every element of unions share the same memory location.

example:         union item
                        {
                            int a;
                            float b;
                            char c;
                        }item 1;

In the above example item, 1 is a variable of data type union item. You can store an integer, a float or a character type value in the variable item 1.



4) Pointer Data Type:

A pointer is a special or most important feature of c language that distinguish C from most of the other language.

In the computer system, memory is composed of several bytes and each byte has its unique address. An address of a memory location can be stored in a special variable called a pointer variable. 

What is Pointer Variable?

A pointer variable is a variable that contains the address of another variable. Let assume Z is a pointer variable then the address of variable x can be assigned to z.

How we assigned the address of variable?

example:  z=&x;

How we declare pointer variable?

A pointer variable can be declared in the same way as the other variable but an asterisk(*) symbol should precede the variable name.

example:    int *ptr;

Here ptr is a pointer variable pointing to an integer type variable.




Sharing Is Caring...

Comments :

Post a Comment