- Get link
- X
- Other Apps
Structure
A structure is a similar to records.It stores related information about an entity.Structure is basically a user define data type that can store related information(even of different data types)together.The major difference between a structure and an array is that, an array is that, an array contains related information of the same data type.
A structure is a collection of variables under a single name. The variable within structure are of different data types and each has a name that is used to select it from the structure.
Structure declaration
A structure is declared using the keyword struct followed by a structure name.
Ex: struct struct_name
{
data_type var-name
data_type var-name;
.....
};
Write a program using structures to read and display the information about a student.
#include<stdio.h>
#include<conio.h>
void main()
{
struct student
{
int roll;
char name[20];
float fees;
char dob[20];
};
struct student std1;
clrscr();
printf("\n Enter the roll number:");
scanf("%d",&std1.roll);
printf("\n Enter the name");
scanf("%s",std1.name);
printf("\n Enter the fees");
scanf("%s",std1.fees);
printf("\n Enter the dob");
scanf("%s",std1.dob);
printf("\n *************student's details******");
printf("\n Roll no.=%d",std1.roll);
printf("\n name=%s",std1.name);
printf("\n fees=%f",std1.fees);
printf("\n dob=%s",std1.dob);
getch();
}
Output
Enter the roll number:1
Enter the name : Rahul
Enter the fees:5200
Enter the dob: 25/09/1995
************student's details*****
roll=1
name=Rahul
fees=5200
dob=25/09/1995
Comments
Post a Comment