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

For any given matrix find the path from the start to the end which gives the maximum sum. Traverse only right or down. Example: starting index is 15 (left top) and ending index is 10 (bottom right) 15 25 30 45 25 60 70 75 10 O/P:15->45->70->75->10 sum is 215

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