Dynamic SensorData Allocation

L#include <iostream>
using namespace std;

// Write your struct and dynamic allocation code here
 struct SensorData{
    int x,y,z;
};
int main() {
    int x, y, z;
    cin >> x >> y >> z;
   SensorData* s=new SensorData{x,y,z};
    // Write your dynamic allocation logic here
cout<<s->x<<" "<<s->y<<" "<<s->z;
delete s;
    return 0;
}

Solving Approach

how to do dynamic memory allocation for structures , create a pointer of structure type, using new give the structure type, initialization can be done using {} or by accessing the values inside structure. like using -> , don't use '.' 

 

 

 

 

 

 

Upvote
Downvote
Loading...

Input

3 4 5

Expected Output

3 4 5