Dynamic SensorData Allocation

#include <iostream>
using namespace std;

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

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

    // Write your dynamic allocation logic here
    SensorData *sensorData_ptr = new SensorData;

    sensorData_ptr->x = x;
    sensorData_ptr->y = y;
    sensorData_ptr->z = z;

    std::cout << sensorData_ptr->x << " " << sensorData_ptr->y << " " << sensorData_ptr->z << std::endl;

    delete sensorData_ptr;

    sensorData_ptr = nullptr;


    return 0;
}

Solving Approach

 

 

 

 

 

 

Upvote
Downvote
Loading...

Input

3 4 5

Expected Output

3 4 5