C++ Program to Display the Details of Student Using Structure

In this program, you'll learn to declare structure student having member variables are roll-no., name and marks. Accept data for one student and display it.



Source Code
#include<iostream>
using namespace std;

struct student
{
    int roll_no;
    char name[20];
    float marks;
};
int main()
{
    struct student s;
    cout<<"Enter student's roll number: ";
    cin>> s.roll_no;
    cout<<"Enter student's name: ";
    cin>> s.name;
    cout<<"Enter student's marks: ";
    cin>> s.marks;
    cout<<"\nStudent's details are:";
    cout<<"\n Roll number=" << s.roll_no;
    cout<<"\n Name=" << s.name;
    cout<<"\n Marks=" << s.marks;
    return 0;
}
Output
Enter student's roll number: 5
Enter student's name: Santosh
Enter student's marks: 75.50

Student's details are:
 Roll number=5
 Name=Santosh
 Marks=75.500000