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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s