C++ program for student details using structure. Structure is a word given to a group of variables of various data types. It’s similar to a class in that they both contain a collection of data of various types. The struct keyword is used to provide a structure type, which is then followed by an identifier. Then, inside the curly braces of that structure, you can declare one or more members declare variables.
using namespace std;
cout << "Enter the Roll Number of the Student" << endl;
for(int i = 0; i < 3; ++i)
s[i].roll = i+1;
cout << "Roll Number" << s[i].roll << "," << endl;
cout << "Enter name ";
cin >> s[i].name;
cout << "Enter marks";
cin >> s[i].marks;
cout << endl;
cout << "Result are here" << endl;
for(int i = 0; i < 3; ++i)
cout << "\nRoll number" << i+1 << endl;
cout << "Name" << s[i].name << endl;
cout << "Marks" << s[i].marks << endl;
Enter the Roll Number of the Student
Enter name aaa
Enter name bbb
Enter name ccc
Result are here
Return Statement in C++
The return statement returns control of the execution flow to the function that called it. There are no conditional statements required in this statement. The flow of the program comes to a halt as soon as the statement is executed, and control is returned to where it was called.
The return statement is used in Java programming to return a value when a block has completed its execution. The return statement inside a loop will cause the loop to break, and the compiler will ignore any subsequent instructions.
A return statement marks the end of a function’s execution and hands control back to the calling function. The calling function continues execution at the place where the call was made. A return statement can give the caller function a value.
Can I use struct in C++ for Student Details Using Structure
Structure is a word given to a group of variables of various data types. It’s similar to a class in that they both contain a collection of data of various types. Consider the following scenario: You’d like to keep track of a person’s name, citizenship number, and annual pay.
Data Structure in C++
A data structure is a collection of diverse sorts and formats of data that may be used to conduct a set of specialised actions. It’s a grouping of data types. It is a method of arranging items in terms of memory, as well as a method of accessing each item using a set of rules.
A struct is a data structure in C++ that can be used to store elements of various data types together. A structure is a user-defined data type in C++. The structure creates a data type that can be used to group items of various data types into a single data type. Using this program we can execute c++ program for student details using structure.