This program defines a student struct that has three members: name, rollno, and age. It then creates an instance of this struct: s. The program prompts the user to enter values for name, rollno, and age using cout statements and cin input. The cin.getline() function is used to read in the name member as a string with a maximum length of 30 characters.
The program then prints the values of each member of s using cout statements. Overall, this program is an example of how to define and use a struct in C++ to store information about a student. It creates an instance of the student struct, prompts the user to enter values for its members, and then prints out the values of each member.
#include<iostream> using namespace std; struct student { char name[30]; int rollno; int age; }; int main() { student s; cout<<"\nEnter Student Name: "; cin.getline(s.name, 30); cout<<"\nEnter Student Roll No: "; cin>>s.rollno; cout<<"\nEnter Student Age: "; cin>>s.age; cout<<"\nStudent Record:"<<endl; cout<<"\nName: "<<s.name<<endl; cout<<"\nRoll No: "<<s.rollno<<endl; cout<<"\nAge: "<<s.age; return 0; }To download raw file Click Here
Enter Student Name: Ram Enter Student Roll No: CS1201 Enter Student Age: 19 Student Record: Name: Ram Roll No: CS1201 Age: 19
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions