I was just wondering what does my OS do if it ran out of memory and I wrote the following code.
int main() {
int *p;
while(1) {
p = new int;
}
}
But as I began to print the address of p and to my surprise the memory usage didn't blow up. It remains constant. And after each iteration the address of p is same as that of previous one.
#include <iostream>
int main() {
int *p;
while(1) {
p = new int;
std::cout << &p << std::endl;
}
}
I was wondering how std::cout << &p << std::endl; is affecting memory?