#include <iostream> #include <cstdint> #include <new> #include <type_traits> using namespace std; typedef struct { int id; int value; } SensorPacket; int main() { int index, id, value; cin >> index >> id >> value; alignas(SensorPacket) uint8_t buffer[(index + 1)*sizeof(SensorPacket)]; SensorPacket *ptr = new (buffer) SensorPacket; ptr->id = id; ptr->value = value; cout << ptr->id << " " << ptr->value; ptr->~SensorPacket(); return 0; }
Test Cases
Test Results
Input
1 50 900
Expected Output
50 900