Saturday, 18 February 2017

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 <iostream>
#include <conio.h>

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: "<<s1.name << endl;
cout<<"ID: "<<s1.id;
}
//Code ends



Share:

0 comments:

Post a Comment