Local variables are stored in an area called ___________
Heap
Permanent storage area
Free memory
Stack
The size of both stack and heap remains the same during run time.
true
false
Choose the statement which is incorrect with respect to dynamic memory allocation
Memory is allocated in a less structured area of memory, known as heap
Used for unpredictable memory requirements
Execution of the program is faster than that of static memory allocation
Allocated memory can be changed during the run time of the program based on the requirement of the program
Which of the following header files must necessarily be included to use dynamic memory allocation functions?
stdlib.h
stdio.h
memory.h
dos.h
What will be the output of the following C code if the input entered as first and second number is 5 and 6 respectively? #include<stdio.h> #include<stdlib.h> main() { int *p; p=(int*)calloc(3*sizeof(int)); printf("Enter first number\n"); scanf("%d",p); printf("Enter second number\n"); scanf("%d",p+2); printf("%d%d",*p,*(p+2)); free(p); }
56
Address of the locations where the two numbers are stored
57
error
In the function malloc(), each byte of allocated space is initialized to zero
true
false
Which of the following functions allocates multiple blocks of memory, each block of the same size?
malloc()
realloc()
calloc()
free()
A condition where in memory is reserved dynamically but not accessible to any of the programs is called ___________
Memory leak
Dangling pointer
Frozen memory
Pointer leak
What will happens if the statement free(a) is removed in the following C code?
In the function realloc(), if the new size of the memory block is larger than the old size, then the added memory ___________is initialized to junk values
is initialized to junk values
is initialized to zero
results in an error
is not initialized
The free() function frees the memory state pointed to by a pointer and returns ___________
What will be the output of the following C code if it is executed on a 32 bit processor? #include<stdio.h> #include<stdlib.h> int main() { int *p; p = (int *)malloc(20); printf("%d\n", sizeof(p)); free(p); return 0; }
2
4
8
junk value
The number of arguments taken as input which allocating memory dynamically using malloc() is ___________
0
1
2
3
Suppose we have a one dimensional array, named ‘x’, which contains 10 integers. Which of the following is the correct way to allocate memory dynamically to the array ‘x’ using malloc()?
x=(int*)malloc(10);
x=(int*)malloc(10,sizeof(int));
x=malloc(int 10,sizeof(int));
x=(int*)malloc(10*sizeof(int));
What will be the error (if any) in the following C code?