C++ program of calling a structure in a function

In this program we will learn, how to call a structure inside a function and insert its values outside the main()..

The code is given below with screenshot.


//Code starts


#include

#include


using namespace std;


struct student{

int id;

char name[15];

};


void show (student s1);


int main()


{

student s1;

show (s1);

getch();

}


void show (student s1)

{

cout<<“Enter Student name”<<endl;

cin>>s1.name;

cout<<“Enter your Roll Number”<<endl;

cin>>s1.id;

cout<<“Name: “<

cout<<“ID: “<<s1.id;

}

//Code ends


Output:

Advertisements

C++ structure program of person

In this program we will create structure of person enter data in structure and also show the entered data.

The code is given below.

//Code Starts

#include<iostream>

#include<conio.h>

using namespace std;

struct person

{

char name[15];

char age[2];

char father_name[20];

char adress[40];

char phone[11];

};

int main()

{

person p;

cout<<“Enter Name “<<endl;

cin>>p.name;

cout<<“Enter Father’s Name “<<endl;

cin>>p.father_name;

cout<<“Enter Age “<<endl;

cin>>p.age;

cout<<“Enter Adress “<<endl;

cin>>p.adress;

cout<<“Enter Mobile Number “<<endl;

cin>>p.phone;

cout<<“Your Entered Data :”<<endl;

cout<<p.name<<endl;

cout<<p.age<<endl;

cout<<p.father_name<<endl;

cout<<p.adress<<endl;

cout<<p.phone<<endl;

getch();

}

//Code Ends

OUTPUT: