xxxxxxxxxx
#include <iostream>
#include <string>
using namespace std;
struct car{
string name;
string color;
int maxSpeed;
int model;
};
car fun (car *x){
cout << "Name: " ;
cin >> x->name;
cout << "Model: ";
cin >> x->model;
cout << "Color: ";
cin >> x->color;
cout << "Maximum speed: ";
cin >> x->maxSpeed;
return *x;
}
int main(){
car c1;
fun (&c1);
car c2 = c1;
cout << "Name: " << c2.name <<endl;
cout << "Model: " << c2.model <<endl;
cout << "Color: " << c2.color <<endl;
cout << "Maximum speed: " << c2.maxSpeed <<endl;
}
xxxxxxxxxx
#include <iostream>
#include <string>
using namespace std;
struct car{
string name;
string color;
int maxSpeed;
int model;
};
void fun (car x){
cout << "Name: " << x.name << endl;
cout << "Model: " << x.model << endl;
cout << "Color: " << x.color << endl;
cout << "Maximum speed: " << x.maxSpeed << endl;
}
int main(){
car c1 ={ "BMW","Red",200,2019 };
car *c2 = &c1;
cout << c2 -> color;
}