How is dynamically allocated space freed when a program is interrupted using Ctrl-C?

前端 未结 4 863
遇见更好的自我
遇见更好的自我 2020-12-17 21:12

Given the following code:

#include 

int main()
{
    int *p;
    p = (int *)malloc(10 * sizeof(int));

    while(1);
    return 0;
}
<         


        
4条回答
  •  情书的邮戳
    2020-12-17 21:38

    By the way (in addition to Seth Carnegie said):

    Using the routines in you can catch the SIGINT signal (interrupt) to handle Ctrl+C in any way, for example to clean up any important resources, not only the memory (like closing files, thus avoiding the loss of any buffered and not-yet-written content, or closing network connections gently).

提交回复
热议问题