C Programming Memory Allocation Online Test. C Programming Free Test
C Programming Memory Allocation Online Test
Finish Quiz
0 of 23 questions completed
Questions:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
Information
C Programming Memory Allocation Online Test. C Programming Question and Answers in English. C Programming Memory Allocation Online mock test paper is free for all students and Very Helpful for Exam Preparation. C Programming Memory Allocation Online Quiz. C Programming Online Mock test for Memory Allocation Topic. Here we are providing C Programming Memory Allocation Online Test Series in English. Check C Programming Mock Test Series 2019-2019.
This paper has 30 questions.
Time allowed is 30 minutes.
The C Programming online Mock Test Exam is Very helpful for all students. Now Scroll down below n click on “Start Quiz” or “Start Test” and Test yourself.
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading...
You must sign in or sign up to start the quiz.
You have to finish following quiz, to start this quiz:
Results
0 of 23 questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 points, (0)
Average score |
|
Your score |
|
Categories
- Not categorized 0%
Pos. | Name | Entered on | Points | Result |
---|---|---|---|---|
Table is loading | ||||
No data available | ||||
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- Answered
- Review
-
Question 1 of 23
1. Question
Which header file should be included to use functions like malloc() and calloc()?
Correct
Incorrect
-
Question 2 of 23
2. Question
What function should be used to free the memory allocated by calloc() ?
Correct
Incorrect
-
Question 3 of 23
3. Question
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; } Correct
Incorrect
-
Question 4 of 23
4. Question
Specify the 2 library functions to dynamically allocate memory?
Correct
Incorrect
-
Question 5 of 23
5. Question
What will be the output of the program?
#include
#include int main() { int *p; p = (int *)malloc(20); /* Assume p has address of 1314 */ free(p); printf("%u", p); return 0; } Correct
Incorrect
-
Question 6 of 23
6. Question
What will be the output of the program (16-bit platform)?
#include
#include int main() { int *p; p = (int *)malloc(20); printf("%d\n", sizeof(p)); free(p); return 0; } Correct
Incorrect
-
Question 7 of 23
7. Question
What will be the output of the program?
include
#include int main() {# char *s; char *fun(); s = fun(); printf("%s\n", s); return 0; } char *fun() { char buffer[30]; strcpy(buffer, "RAM"); return (buffer); } Correct
The output is unpredictable since buffer is an auto array and will die when the control go back to main. Thus s will be pointing to an array , which not exists.Incorrect
The output is unpredictable since buffer is an auto array and will die when the control go back to main. Thus s will be pointing to an array , which not exists. -
Question 8 of 23
8. Question
What will be the output of the program?
#include
#include int main() { union test { int i; float f; char c; }; union test *t; t = (union test *)malloc(sizeof(union test)); t->f = 10.10f; printf("%f", t->f); return 0; } Correct
Incorrect
-
Question 9 of 23
9. Question
Assume integer is 2 bytes wide. How many bytes will be allocated for the following code?
#include
#include #define MAXROW 3 #define MAXCOL 4 int main() { int (*p)[MAXCOL]; p = (int (*) [MAXCOL])malloc(MAXROW *sizeof(*p)); return 0; } Correct
Incorrect
-
Question 10 of 23
10. Question
Assume integer is 2 bytes wide. What will be the output of the following code?
#include
#include #define MAXROW 3 #define MAXCOL 4 int main() { int (*p)[MAXCOL]; p = (int (*) [MAXCOL])malloc(MAXROW *sizeof(*p)); printf("%d, %d\n", sizeof(p), sizeof(*p)); return 0; } Correct
Incorrect
-
Question 11 of 23
11. Question
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; } Correct
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.
Incorrect
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.
-
Question 12 of 23
12. Question
Point out the error in the following program.
#include
#include int main() { int *a[3]; a = (int*) malloc(sizeof(int)*3); free(a); return 0; } Correct
We should store the address in a[i]Incorrect
We should store the address in a[i] -
Question 13 of 23
13. Question
Point out the error in the following program.
#include
#include int main() { char *ptr; *ptr = (char)malloc(30); strcpy(ptr, "RAM"); printf("%s", ptr); free(ptr); return 0; } Correct
Answer: ptr = (char*)malloc(30);Incorrect
Answer: ptr = (char*)malloc(30); -
Question 14 of 23
14. Question
Which of the following statement is correct prototype of the malloc() function in c ?
Correct
Incorrect
-
Question 15 of 23
15. Question
Point out the correct statement which correctly free the memory pointed to by ‘s’ and ‘p’ in the following program?
#include
#include int main() { struct ex { int i; float j; char *s }; struct ex *p; p = (struct ex *)malloc(sizeof(struct ex)); p->s = (char*)malloc(20); return 0; } Correct
Incorrect
-
Question 16 of 23
16. Question
Point out the correct statement which correctly allocates memory dynamically for 2D array following program?
#include
#include int main() { int *p, i, j; /* Add statement here */ for(i=0; i3; i++) { for(j=0; j4; j++) { p[i*4+j] = i; printf("%d", p[i*4+j]); } } return 0; } Correct
Incorrect
-
Question 17 of 23
17. Question
malloc() returns a float pointer if memory is allocated for storing float‘s and a double pointer if memory is allocated for storing double‘s.
Correct
Incorrect
-
Question 18 of 23
18. Question
malloc() allocates memory from the heap and not from the stack.
Correct
Incorrect
-
Question 19 of 23
19. Question
malloc() returns a NULL if it fails to allocate the requested memory.
Correct
Incorrect
-
Question 20 of 23
20. Question
If malloc() successfully allocates memory it returns the number of bytes it has allocated.
Correct
Syntax: void *malloc(size_t size);
The malloc() function shall allocate unused space for an object whose size in bytes is specified by size and whose value is unspecified.
The order and contiguity of storage allocated by successive calls to malloc() is unspecified. The pointer returned if the allocation succeeds shall be suitably aligned so that it may be assigned to a pointer to any type of object and then used to access such an object in the space allocated (until the space is explicitly freed or reallocated). Each such allocation shall yield a pointer to an object disjoint from any other object. The pointer returned points to the start (lowest byte address) of the allocated space. If the space cannot be allocated, a null pointer shall be returned. If the size of the space requested is 0, the behavior is implementation-defined: the value returned shall be either a null pointer or a unique pointer.
Incorrect
Syntax: void *malloc(size_t size);
The malloc() function shall allocate unused space for an object whose size in bytes is specified by size and whose value is unspecified.
The order and contiguity of storage allocated by successive calls to malloc() is unspecified. The pointer returned if the allocation succeeds shall be suitably aligned so that it may be assigned to a pointer to any type of object and then used to access such an object in the space allocated (until the space is explicitly freed or reallocated). Each such allocation shall yield a pointer to an object disjoint from any other object. The pointer returned points to the start (lowest byte address) of the allocated space. If the space cannot be allocated, a null pointer shall be returned. If the size of the space requested is 0, the behavior is implementation-defined: the value returned shall be either a null pointer or a unique pointer.
-
Question 21 of 23
21. Question
Can I increase the size of dynamically allocated array?
Correct
Use realloc(variable_name, value);Incorrect
Use realloc(variable_name, value); -
Question 22 of 23
22. Question
Can I increase the size of statically allocated array?
Correct
Incorrect
-
Question 23 of 23
23. Question
When we dynamically allocate memory is there any way to free memory during run time?
Correct
Using free()Incorrect
Using free()