- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Program to Store Information of a Student in a Structure
A structure is a collection of items of different data types. It is very useful in creating complex data structures with different data type records. A structure is defined with the struct keyword.
An example of a structure is as follows.
struct employee { int empID; char name[50]; float salary; };
A program that stores student information in a structure is given as follows.
Example
#include <iostream> using namespace std; struct student { int rollNo; char name[50]; float marks; char grade; }; int main() { struct student s = { 12 , "Harry" , 90 , 'A' }; cout<<"The student information is given as follows:"<<endl; cout<<endl; cout<<"Roll Number: "<<s.rollNo<<endl; cout<<"Name: "<<s.name<<endl; cout<<"Marks: "<<s.marks<<endl; cout<<"Grade: "<<s.grade<<endl; return 0; }
Output
The student information is given as follows: Roll Number: 12 Name: Harry Marks: 90 Grade: A
In the above program, the structure is defined before the main() function. The structure contains the roll number, name, marks and grade of a student. This is demonstrated in the following code snippet.
struct student { int rollNo; char name[50]; float marks; char grade; };
In the main() function, an object of type struct student is defined. This contains the roll number, name, marks and grade values. This is shown as follows.
struct student s = { 12 , "Harry" , 90 , 'A' };
The structure values are displayed in the following manner.
cout<<"The student information is given as follows:"<<endl; cout<<endl; cout<<"Roll Number: "<<s.rollNo<<endl; cout<<"Name: "<<s.name<<endl; cout<<"Marks: "<<s.marks<<endl; cout<<"Grade: "<<s.grade<<endl;
- Related Articles
- C++ Program to Store and Display Information Using Structure
- C++ program to store student roll and name using map STL
- C program to store the car information using dynamic linked list.
- C program to store Student records as Structures and Sort them by Name
- C# Program to get information about a file
- Write a query to store and retrieve book information in the database (DBMS)?
- What is the basic structure of a C# program?
- C++ Program Structure
- Write a C program to display the size and offset of structure members
- Write a structure in local scope program using C language
- C++ Program to Add Complex Numbers by Passing Structure to a Function
- What are the structure of DES in information security?
- C program to store inventory system using structures
- How to define a structure in C#
- Explain the basic structure of a program in Java?

Advertisements