This is a snippet of code that I took from a bigger one. I need to figure out whether or not what I'm printing is garbage and how to change it for it to print the value I need.
I need it to print the value of int id instead of whatever it's printing. The output was 10813776 in this run and it, of course, changes whenever I change some code or relaunch DevC++.
The code is:
#include <iostream>
#include <memory> //Memory allocation (malloc)
using namespace std;
int main(){
    int id = 0;
    int nMemory = 0;
    int * pMemory;
    pMemory = (int *) malloc(20 * sizeof(int));
    
    while(id < 20){
        if (pMemory != NULL){
            cout << "Numbers in memory: " << endl;
            pMemory = new int[id];
            nMemory = *pMemory;
            cout << nMemory << endl;
        }
        id++;
    }
    delete pMemory;
    
    return 0;
}
 
     
    