Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

struct and pointer c++

#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;
}
 
PREVIOUS NEXT
Tagged: #struct #pointer
ADD COMMENT
Topic
Name
7+2 =