Structures
- Collection of related variables
- derived data types
- Contain variables of many different data types
- Individual structure elements are known as members
- The general syntax structure declaration is:
struct name_tag{
member_1;
member_2;
member_3;
...
member_n;
};
- "struct" is a keyword
- name_tag is a name that identifies the structure
- The individual members can be ordinary variables, pointers, arrays and other structures
- Example
struct student{
int matrikno;
char name[40];
float height;
};
- A structure member can be accessed by a dot operator
- The syntax of a dot operator is:
- variable.member
- where variable refers to the name of a structure type variable and member represents to the name of a member within a structure
- Example
#include
struct studentdate{
int matno;
int month;
int date;
int year;
};
int main (void){
studentdate joiningdate;
scanf("%d", &joiningdate.matno);
scanf("%d", &joiningdate.month);
scanf("%d", &joiningdate.date);
scanf("%d", &joiningdate.year);
printf("%d\n", joiningdate.matno);
printf("%d\n", joiningdate.month);
printf("%d\n", joiningdate.date);
printf("%d\n", joiningdate.year);
return 0;
}
No comments:
Post a Comment