27. Dynamic SensorData Allocation

Back To All Submissions
Previous Submission
Next Submission
#include <iostream>
using namespace std;

// Write your struct and dynamic allocation code here
struct SensorData{
    int x;
    int y;
    int z;

    SensorData(int x, int y, int z) {
        this->x=x;
        this->y=y;
        this->z=z;
    };
};

int main() {
    int x, y, z;
    cin >> x >> y >> z;

    // Write your dynamic allocation logic here
    SensorData* sensor_data = new SensorData(x, y, z);

    cout << sensor_data->x << " " << sensor_data->y << " " << sensor_data->z;

    delete sensor_data;

    return 0;
}

Solving Approach

 

 

 

 

 

 

Was this helpful?
Upvote
Downvote