Passing structures(structs) in to functions

#include <iostream>

using namespace std;
struct stationary{
int price;
char book[30];
char author[30];
};
void myfunction(int ,char[],char[]);//function prototype for way 1
int myfunction1(struct stationary );//function protype for way2
int main()
{
    struct stationary obj={6,"engineering circuit analysis ","willuam hayt "};//common struct for both ways
    myfunction(obj.price,obj.book,obj.author);//calling function by way 1

    cout<<endl<<endl<<"printing the same statement by method 2"<<endl;


    cout<<endl<<obj.book<<"was written by "<<obj.author<<"and its price = "<<myfunction1(obj)<<endl;//here we return price by way 2

}
void myfunction(int c,char a[],char b[]){//way 1 function
cout<<a<<" was written by"<<b<<" and its price = "<<c<<endl;
}

int myfunction1(struct stationary obj1){ //way 2 function
return obj1.price;
}






Previous
Next Post »

Comments:

Disqus Shortname