Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

struct and return functions in c++

#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;
}
 
PREVIOUS NEXT
Tagged: #struct #return #functions
ADD COMMENT
Topic
Name
5+1 =