#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;
}
#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;
}
Code Example |
---|
Cpp :: calloc c++ |
Cpp :: functors in c++ |
Cpp :: 2-Dimensional array in c++ |
Cpp :: c++ structure |
Cpp :: c++ vectors |
Cpp :: delete dynamic array c++ |
Cpp :: declare nullptr c++ |
Cpp :: cpp vector2 |
Cpp :: 2d array c++ |
Cpp :: c++ power |
Cpp :: c++ array size |
Cpp :: string to integer in c++ |
Cpp :: case label in c++ |
Cpp :: c++ add to array |
Cpp :: c++ average |
Cpp :: c++ basic snippet |
Cpp :: string split by space c++ |
Cpp :: What is the "--" operator in C/C++? |
Cpp :: how to empty string c++ |
Cpp :: c #define |
Cpp :: how to make Dijkstra in c++ |
Cpp :: convert kelvin to Fahrenheit |
Cpp :: getline |
Cpp :: linked list in c++ |
Cpp :: create matrix cpp |
Cpp :: two elements with difference K in c++ |
Cpp :: c ++ split_string |
Cpp :: do while c++ |
Cpp :: int max in c++ |
Cpp :: reference c++ |