Structures

Structure is a datatype.
Structure is the collection of data.
The struct keyword is used to define a structure.

Example for structure declaration

struct student
{
          char name[100];
          int age;
          float average;
}

structure variables are declared next;
Then using dot operator the members of the structure variables can be accessed.

Program

#include <iostream>
using namespace std;
struct student
{
    char name[10];
    int age;
};
int main()
{
    student s1;
    cin.get(s1.name,50);
    cin>>s1.age;
    cout<<"name:"<<s1.name<<endl;
    cout<<"age:"<<s1.age;
    return 0;
}

Output

John Smith                                                                                                                                     
21                                                                                                                                             
name:John Smith                                                                                                                                
age:21 

Comments

Popular posts from this blog

C program to print the following Pattern

c++ program to print string along the diagonals of the matrix.

Kollywood Game