在C語言中,內存管理是由程序員自己負責的。以下是一些常用的內存管理操作:
int *ptr; ptr = (int *)malloc(sizeof(int));
free(ptr);
ptr = realloc(ptr, newSize);
memset(ptr, 0, sizeof(ptr));
需要注意的是,在使用malloc()、free()和realloc()函數時要確保內存的正確釋放,避免內存泄漏和懸空指針的問題。