Why did you comment the cout and cin? I want my program to work regarding what the user inputs. That's why I am using Dynamic 2D array. Or is that not possible?
@DeathLeap, anup30 was just testing the code with variables without getting them from user input, see int row=3 and column=5. You can take that part out and still prompt the user for their input.
My second question is, what happens if a "memory leak" occurs?
in your program, actually there wont be any problem if you don't delete. OS will automatically delete after program exit.
but in large/long running program, when you don't need previously allocated memory anymore, you have to say the computer that previously called memory to De-allocate, by delete/delete[]
so the computer(OS) can use the memory for another program or you can use that memory for another task later. otherwise, it will quickly reach out of ram's capacity.
so its good practice to know/use them from beginning.
EDIT: and you can hang computer by memory leaking!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// !!!!!! program to hang Computer !!!!!!!
#include <iostream>
usingnamespace std;
int main()
{
unsignedlonglongint *pt= newunsignedlonglongint;
unsignedlonglongint size = 4e9; // 4e9 == 4 billion, requires approx 16GB Ram.
unsignedlonglongint i;
for(i=0; i<size; i++)
{
//delete pt; //disabled to leak memory & hang pc
pt = newunsignedlonglongint;
}
return 0;
}
if your PC has more than 16GB Ram, increase the size in line8 or use infinite loop!!