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
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
0 comments:
Post a Comment