NVIDIA Interview Question
Software Engineer / Developersseems to be allocating the mentioned amount of memory on heap, but then the while loop keeps moving for-ever so eventually there wont be space to be allocated any more, and then for crossing the threshold amount of heap the process would be killed by OS.
The size of the process keeps on growing(ps -fl) and the pgm crash when it runs out of memory
Malloc would simply start failing when it can no longer allocate more memory. The program will continue to run...
main (){
int *p;
while(1){
p=(int *)malloc(1024*1024);
if(!p)
printf("no more\n");}
}
output:
aftr some time
no more
no more
no more
.....
so programm will be moved infinite time
Malloc would simply start failing when it can no longer allocate more memory. The program will continue to run...
- Lokesh October 07, 2009