Professional Documents
Culture Documents
How To Pass Structures To Functions?
How To Pass Structures To Functions?
Structure eg
#include <iostream>
struct person
char name[50];
int age;
float salary;
};
int main()
person p1;
cout<<"Enter name:";
cin>>p1.name;
cout<<"Enter age:";
cin>>p1.age;
cin>>p1.salary;
return 0;
Switch eg
#include <iostream>
int main()
int choice;
cin>>choice;
switch(choice)
case 1:
break;
case 2:
break;
case 3:
break;
default:
cout<<"you selected wrong choice ";
break;
return 0;
If else eg
#include <iostream>
int main()
int choice;
cin>>choice;
if(choice==1)
else
return 0;
#include <iostream>
struct person
char name[50];
int age;
float salary;
};
int main()
cout<<"Enter name:";
cin>>p1.name;
cout<<"Enter age:";
cin>>p1.age;
cin>>p2.name;
cin>>p2.age;
cin>>p2.salary;
return 0;