Saturday, 9 December 2017

Structure C Language

Structure  C Language

A structure is user defined data type which is used to store record based data. Structure is useful when there is a need to process record type data for example student record which is a combination of more than variable (roll,name,class,marks etc). Structure encapsulates more than one variable into a single logical unit. Without structure, processing of record based data is not an easy task. Programmer need to declare many variables with different name. Which increase complexity?

Structure minimize programmer task for handling record base data. You need to make a single variable which will hold many data into a single unit. Data setting totally depend up to user. Array of structure is also useful to process more than record.

Syntax for define a structure

struct <structure_name>
    data_type  Var_Name1;
   data_type   Var_Name2;
   data_type Var_NameN;


Dot (.) Operator

Dot (.) operator is use to access structure member for read and write.

Example :


struct stu
     int roll;
     char name[10];
     float marks;
void main()
     struct stu ob;
     printf("Enter Roll>> ");
     printf("Enter Name>> ");
     printf("Enter Marks>> ");
     printf("\nPrinting Data\n");