Telemetry Packet Memory Cleanup

#include <iostream>
using namespace std;

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

    // --- Dynamic Allocation Logic ---

    // 1. Allocate memory for the first packet
    int* packet1 = new int;
    // 2. Store the first computed value
    *packet1 = firstValue;
    // 3. Delete the old packet before reusing the pointer (or creating a new one)
    delete packet1;

    // 4. Allocate a new packet for the second value
    int* packet2 = new int;
    // 5. Store the second computed value
    *packet2 = secondValue;

    // 6. Print the final packet value (the second one)
    cout << *packet2 << endl;

    // 7. Delete the final packet before program exit
    delete packet2;

    return 0;
}

Solving Approach

 

 

 

 

 

 

Upvote
Downvote
Loading...

Input

25 40

Expected Output

40