C PROGRAMMING

write a c program to store details or record of a student using structure

C program to store details or record of a student using structure?

Structure :

Structure is a user defined data type/structure that can store related information of different data types. structure is a collection of different types of variables under a single name.  Unlike Arrays structures can have variables of many types like integer, char, float etc. While as an array can have only homogeneous data type and a structure can have heterogeneous data types.  

syntax for declaration of structure

 

struct structure_name
{
datatype variable_name1;
datatype variable_name2;
..
..
};

 

 

#include <stdio.h>
/*structure creation*/
struct student
{
char name[50]; // structure member1
int id; // structure member2
char branch[20]; // structure member3
int age; // structure member4
char place[50]; // structure member5
} std; // structure variable
main()
{
/*Taking information from keyboard and store it by using structure variable std*/
printf("Enter Student Informationn");
printf("----------------------------n");
printf("enter name :n");
scanf("%s",std.name);

printf("enter id :n");
scanf("%d",&std.id);

printf("enter dept name :n");
scanf("%s",&std.branch);

printf("enter age :n");
scanf("%d",&std.age);

printf("enter location :n");
scanf("%s",std.place);

/*Displaying student information */
//Accessing information by using structure variable std
printf("Displaying Student Informationn");
printf("----------------------------n");

printf(" name: %sn", std.name);
printf(" id: %d n", std.id);
printf(" branch: %s n", std.branch);
printf(" age: %dn", std.age);
printf(" place: %s n", std.place);
getch();
}

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button