C Program to Store Information of a Student Using Structure

Sreemeenakshi V
1 min readJun 11, 2021

--

Language Used: C

Structures in C:

In C programming, a struct or structure is a collection of variables that can be of different data types under a single name.

Syntax of struct:

struct structureName 
{
dataType member1;
dataType member2;
...
};

When a struct type is declared, no storage or memory is allocated. To allocate memory of a given structure type and work with it, we need to create variables.

How to create struct variables?

Method 1:

struct Person
{
char name[40];
int RollNo;
float Marks;
} person1, person2, p[20];

Method 2:

struct Person
{
char name[40];
int RollNo;
float Marks;
};

int main()
{
struct Person person1, person2, p[20];
return 0;
}

How to access members of a struct?

There are 2 types of operators for accessing:

  1. . - Member operator
  2. -> - Structure pointer operator

If you want to access the marks of person1. Here’s how you can do it.

person1.Marks

Program

Output

Enter information:
Enter name: Meeya
Enter roll number: 19
Enter marks: 97.5
Displaying Information:
Name: Meeya
Roll number: 19
Marks: 97.5

Description:

Here, we have first created a struct variable where different variable like char, int, float are used for Name, roll number and marks respectively.

Using fgets and scanf functions the input data are read and are stored in their respective variables.

After getting input, the data are displayed to the user.

For any Educational Assisstance,

Refer: https://www.guvi.in/

--

--

No responses yet