HackerRank C++ Structs


struct is a way to combine multiple fields to represent a composite data structure, which further lays the foundation for Object Oriented Programming. For example, we can store details related to a student in a struct consisting of his age (int), first_name (string), last_name (string) and standard (int).

  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7. struct Student
  8. {
  9. int age,standard;
  10. string first_name,last_name;
  11. };
  12. int main()
  13. {
  14. Student st;
  15. cin >> st.age >> st.first_name >> st.last_name >> st.standard;
  16. cout << st.age << " " << st.first_name << " " << st.last_name << " " << st.standard;
  17. return 0;
  18. }

download android app