fork download
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5. struct Students
  6. {
  7. string name; // Unlike classes we can't initlize any data member within structure.
  8. int ID;
  9. string Class;
  10. char Section;
  11. };
  12.  
  13. void Print(struct Students x) // Function for printing student information
  14. {
  15. cout << "Student name is : " << x.name << endl;
  16. cout << "Student Id is : " << x.ID << endl;
  17. cout << "Students studies in class " << x.Class << " and section is " << x.Section << endl;
  18. }
  19.  
  20. int main()
  21. {
  22. struct Students first;
  23. first.name = "JOHN";
  24. first.ID = 1;
  25. first.Class = "Computer Science";
  26. first.Section = 'B';
  27.  
  28. Print(first);
  29.  
  30. /*
  31.   Another and simple way of initializing first -
  32.   struct Students first = {"JOHN", 1, "Computer Science", 'B'};
  33.   */
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 4548KB
stdin
Standard input is empty
stdout
Student name is : JOHN
Student Id is : 1
Students studies in class Computer Science and section is B