Structures in C++ :

Introduction to Structures in C++ language :

C language Structure (.) Operator or sizeof() - Structures are one of the two important building blocks in the understanding of classes and objects. A structure is a collection of data while a class is a collection of data and functions. In other words, we can say, a structure plus related functions make a class. Technically, there is no difference between a structure and a class. The keyword struct tells the compiler that a structure is begin defined.

Example :

  1. /* Description: store students name in C++ language */
  2. #include<iostream>
  3. using namespace std;
  4. struct data{
  5. char name[20];
  6. }info[21];
  7. int main()
  8. {
  9. int i,j;
  10. cout<<" Enter how many student data you want to load ( MAX 20 ): ";
  11. cin>>i;
  12. for(j=1;j<=i;j++)
  13. {
  14. cout<<"\n No. "<&l<j <<" Student name : ";
  15. cin>>info[j].name;
  16. }
  17. cout<< "\n ------ DATA STOR COMPLETED ------- \n\n";
  18. for(j=1;j<=i;j++)
  19. {
  20. cout<<"\n No. "<&l<j <<" Name: " <<info[j].name;
  21. }
  22. }

Output :

C++ language store students name

Next Update


We Are Currently Working On Our Android Application Development and We already have two YouTube channels their name is CodeX or NightHawk. CodeX is for programming related videos and NightHawk is for online game streaming so please supporting us and Subscribe to our channels, Thank you