Telemetry Packet Memory Cleanup

#include <iostream>
using namespace std;

int main() {
    int firstValue, secondValue;
    cin >> firstValue >> secondValue;

    // Allocate first telemetry packet
    int* packet = new int;
    *packet = firstValue;

    // Delete old packet before reusing pointer
    delete packet;

    // Allocate second telemetry packet
    packet = new int;
    *packet = secondValue;

    // Print final packet value
    cout << *packet;

    // Final cleanup
    delete packet;

    return 0;
}

Solving Approach

 

 

 

 

 

 

Upvote
Downvote
Loading...

Input

25 40

Expected Output

40