RejinpaulPlacement
Search

Memory Allocation - C Programming Questions and Answers - RejinpaulPlacement

@ : Home > C Programming > Memory Allocation


Find us on Facebook



Follow us on Google+


Google+

1.
Which header file should be included to use functions like malloc() and calloc()?
Answer & Solution
Answer: (B) stdlib.h
Solution:
No answer description available for this question. Let us discuss.
close
2.
What function should be used to free the memory allocated by calloc() ?
Answer & Solution
Answer: (C) free()
Solution:
No answer description available for this question. Let us discuss. close
3.
How will you free the memory allocated by the following program?

#include
#include
#define MAXROW 3
#define MAXCOL 4
int main()
{
int **p, i, j;
p = (int **) malloc(MAXROW * sizeof(int*));
return 0;
}
Answer & Solution
Answer: (D) free(p);
Solution:
No answer description available for this question. Let us discuss. close
4.
Specify the 2 library functions to dynamically allocate memory?
Answer & Solution
Answer:
(C) malloc() and calloc()
Solution:
No answer description available for this question. Let us discuss.
close
5.
How many bytes of memory will the following code reserve?

#include
#include
int main()
{
int *p;
p = (int *)malloc(256 * 256);
if(p == NULL)
printf("Allocation failed");
return 0;
}
Answer & Solution
Answer: (B) Allocation failed
Solution:
Hence 256*256 = 65536 is passed to malloc() function which can allocate upto 65535. So the memory allocation will be failed in 16 bit platform (Turbo C in DOS).

If you compile the same program in 32 bit platform like Linux (GCC Compiler) it may allocate the required memory.
close