In C++ Structure is a collection of variables of different data types under a single name. It is similar to a class in that, both holds a collecion of data of different data types. For example: You want to store some information about a person: his/her name, citizenship number and salary.

Structure is a constructed building or a specific arrangement of things or people, especially things that have multiple parts. An example of structure is a newly built home. An example of structure is the arrangement of DNA elements. In C++, a structure is a user-defined data type. The structure creates a data type for grouping items of different data types under a single data type. For example: Suppose you need to store information about someone, their name, citizenship, and age.
A STRUCT is a C++ data structure that can be used to store together elements of different data types. In C++, a structure is a user-defined data type. The structure creates a data type for grouping items of different data types under a single data type. It means variables for different individuals will be created.
examples:
#include <iostream>
using namespace std;
struct Person
{
char name[50];
int age;
float salary;
};
int main()
{
Person p1;
cout << "Enter Full name: ";
cin.get(p1.name, 50);
cout << "Enter age: ";
cin >> p1.age;
cout << "Enter salary: ";
cin >> p1.salary;
cout << "\nDisplaying Information:" << endl;
cout << "Name: " << p1.name << endl;
cout <<"Age: " << p1.age << endl;
cout << "Salary: " << p1.salary;
return 0;
}
output
Enter Full name: your name
Enter age: 12
Enter salary: 100000.0
Displaying Information:
Name: your name
Age: 12
Salary: 100000.0
3 Comments
[…] variable is a name given to a memory location. It is the basic unit of storage in a program. The value stored in a variable can be […]
[…] is a collection of similar data elements stored at contiguous memory locations. It is the simplest data structure where each data element can be accessed directly by only using its index […]
[…] the Select a wizard window, expand C/C++, select C++ Project, and then click Next. In the Create a C++ Project window, in the Project name field, enter a name for the C++ project. From the Project type […]