We use struct keyword to create a structure in C. The struct keyword is a short form of structured data type.
struct struct_name {
DataType member1_name;
DataType member2_name;
DataType member3_name;
…
};
struct time
{
int second;
int minute;
int hour;
} t[3];#include <stdio.h>
/* Created a structure here. The name of the structure is * StudentData. */
struct StudentData{
char *stu_name;
int stu_id;
int stu_age;
};
int main()
{
/* student is the variable of structure StudentData*/
struct StudentData student;
/*Assigning the values of each struct member here*/
student.stu_name = "Crazy";
student.stu_id = 042019;
student.stu_age = 21;
/* Displaying the values of struct members */
printf("Student Name is: %s", student.stu_name);
printf("\nStudent Id is: %d", student.stu_id);
printf("\nStudent Age is: %d", student.stu_age);
return 0;
}
Student Name is: Crazy Student Id is: 042019 Student Age is: 21