Placement New Static Buffer

#include <iostream>
#include <cstdint>
#include <new>
using namespace std;

typedef struct{
    int id;
    int value;
}Block;


// Define your struct and placement new logic here

int main() {
    int id, value;
    cin >> id >> value;
    alignas(Block) uint8_t buffer[sizeof(Block)]; 
    Block *pack = new (buffer) Block;

    pack->id = id;
    pack->value = value;

    cout << pack->id <<" " << pack->value;

    // Write your placement new construction code here

    return 0;
}

Solving Approach

 

 

 

 

 

 

Upvote
Downvote
Loading...

Input

7 42

Expected Output

7 42