Struct

Structure Definition
A data type to store group of data with different data type. Component of struct called as member, field or element. Struct also called as Record.

How to declare Struct
struct name_of_the_struct{
     dataType1 name_field1;
     dataType2 name_field2;
};

Variable of the struct also can be defined when being declared
struct name_of_the_struct{
     dataType1 name_field1;
     dataType2 name_field2;
}name_variable_structure;

How to accessing the struct from the main program
Example :

struct data{
    char name[10];
    int age;
    int class;
}student[100];

int main(){
   data student[100];
   .....
   .....
   return 0;
}

How to use the struct on the main program
Example :

Example :

struct data{
    char name[10];
    int age;
    int class;
}student[100];

int main(){
   data student[100];
   scanf("%s %d %d", &student.name, &student.age, &student.class);
   printf("%s %d %d", student.name, student.age, student.class);
   return 0;
}

Komentar

Postingan populer dari blog ini

Function and Recursion (28 November 2018)

File Processing (5 December 2018)

Sorting and Searching (12 December 2018)