Core Dump/Segmentation fault is a specific kind of error caused by accessing memory that “does not belong to you.” When a piece of code tries… Read More »
Consider the following program, where are i, j and k are stored in memory? (A) i, j and k are stored in stack segment (B)… Read More »
What is the problem with following code? (A) Compiler Error: free can’t be applied on NULL pointer (B) Memory Leak (C) Dangling Pointer (D) The… Read More »
Which of the following is true? (A) “ptr = calloc(m, n)” is equivalent to following ptr = malloc(m * n); (B) “ptr = calloc(m, n)”… Read More »
What is the return type of malloc() or calloc() (A) void * (B) Pointer of allocated memory type (C) void ** (D) int * Answer:… Read More »
Which of the following is/are true (A) calloc() allocates the memory and also initializes the allocates memory to zero, while memory allocated using malloc() has… Read More »
Output? (A) May not work (B) Works and prints 6 Answer: (A) Explanation: The program is not valid. Try replacing “int *p;” with “int *p… Read More »
Consider the following three C functions : Which of the above three functions are likely to cause problems with pointers? (GATE 2001) (A) Only P3… Read More »
The most appropriate matching for the following pairs (GATE CS 2000) X: m=malloc(5); m= NULL; 1: using dangling pointers Y: free(n); n->value=5; 2: using uninitialized… Read More »
Question: How to deallocate dynamically allocate memory without using “free()” function.
A typical memory representation of C program consists of following sections.
Consider the following prototype of free() function which is used to free memory allocated using malloc() or calloc() or realloc().
Size of dynamically allocated memory can be changed by using realloc(). As per the C99 standard:
The name malloc and calloc() are library functions that allocate memory dynamically. It means that memory is allocated during runtime(execution of the program) from heap… Read More »
Memory leak occurs when programmers create a memory in heap and forget to delete it.
Memory leaks are particularly serious issues for programs like daemons and servers which by definition never terminate.