Practice high-yield Programming & Software Development MCQs on Memory Allocation — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The number of arguments for realloc() function is/are:
Correct Answer: Option C — 2
Detailed Academic Explanation:
As it takes two parameters, one is the pointer to the existing block and the second is the value for new size in integers.
💡Key Conceptual Anchor:Memory Allocation
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C, which header file should be included to use dynamic memory allocation functions?
Correct Answer: Option A — stdlib.h
Detailed Academic Explanation:
stdlib.h is the correct answer to “In C, which header file should be included to use dynamic memory allocation functions”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'malloc' function in C?
Correct Answer: Option A — To allocate dynamic memory
Detailed Academic Explanation:
To allocate dynamic memory is the correct answer to “What is the purpose of the 'malloc' function in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to allocate an array of elements in C?
Correct Answer: Option A — calloc()
Detailed Academic Explanation:
calloc() is the correct answer to “Which function is used to allocate an array of elements in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the 'calloc' function in C do?
Correct Answer: Option A — Allocates and initializes memory to zero
Detailed Academic Explanation:
Allocates and initializes memory to zero is the correct answer to “What does the 'calloc' function in C do”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to change the size of an allocated block of memory in C?
Correct Answer: Option B — realloc()
Detailed Academic Explanation:
realloc() is the correct answer to “Which function is used to change the size of an allocated block of memory in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the return value of the 'malloc' function if it fails to allocate memory?
Correct Answer: Option A — NULL
Detailed Academic Explanation:
NULL is the correct answer to “What is the return value of the 'malloc' function if it fails to allocate memory”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you release dynamically allocated memory in C?
Correct Answer: Option A — free()
Detailed Academic Explanation:
free() is the correct answer to “How do you release dynamically allocated memory in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'memset' function in C?
Correct Answer: Option B — To set memory to zero
Detailed Academic Explanation:
To set memory to zero is the correct answer to “What is the purpose of the 'memset' function in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to copy a block of memory in C?
Correct Answer: Option A — memcpy()
Detailed Academic Explanation:
memcpy() is the correct answer to “Which function is used to copy a block of memory in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the 'free' function in C?
Correct Answer: Option A — To deallocate dynamically allocated memory
Detailed Academic Explanation:
To deallocate dynamically allocated memory is the correct answer to “What is the purpose of the 'free' function in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you check if the 'malloc' function has successfully allocated memory in C?
Correct Answer: Option A — Check if the return value is not NULL
Detailed Academic Explanation:
Check if the return value is not NULL is the correct answer to “How do you check if the 'malloc' function has successfully allocated memory in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to return the number of bytes allocated by 'malloc'?
Correct Answer: Option B — sizeofmalloc()
Detailed Academic Explanation:
sizeofmalloc() is the correct answer to “Which function is used to return the number of bytes allocated by 'malloc'”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the return value of the 'realloc' function if it fails to reallocate memory?
Correct Answer: Option A — NULL
Detailed Academic Explanation:
NULL is the correct answer to “What is the return value of the 'realloc' function if it fails to reallocate memory”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the 'sizeof' operator in C return for a dynamically allocated array?
Correct Answer: Option A — Size of a single element
Detailed Academic Explanation:
Size of a single element is the correct answer to “What does the 'sizeof' operator in C return for a dynamically allocated array”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to allocate memory for an array of character strings in C?
Correct Answer: Option B — calloc()
Detailed Academic Explanation:
calloc() is the correct answer to “Which function is used to allocate memory for an array of character strings in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a segmentation fault in C?
Correct Answer: Option A — An error that occurs when accessing an invalid memory location
Detailed Academic Explanation:
An error that occurs when accessing an invalid memory location is the correct answer to “What is a segmentation fault in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you check if the 'realloc' function has successfully reallocated memory in C?
Correct Answer: Option A — Check if the return value is not NULL
Detailed Academic Explanation:
Check if the return value is not NULL is the correct answer to “How do you check if the 'realloc' function has successfully reallocated memory in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to free allocated memory but does not remove the pointer in C?
Correct Answer: Option B — free()
Detailed Academic Explanation:
free() is the correct answer to “Which function is used to free allocated memory but does not remove the pointer in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the maximum number of bytes that can be allocated using 'malloc' in C?
Correct Answer: Option A — It depends on the system and available memory
Detailed Academic Explanation:
It depends on the system and available memory is the correct answer to “What is the maximum number of bytes that can be allocated using 'malloc' in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the difference between 'malloc' and 'calloc' in C?
Correct Answer: Option A — 'malloc' allocates uninitialized memory, 'calloc' allocates and initializes to zero
Detailed Academic Explanation:
'malloc' allocates uninitialized memory, 'calloc' allocates and initializes to zero is the correct answer to “What is the difference between 'malloc' and 'calloc' in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C, which function is used to allocate memory from the stack?
Correct Answer: Option C — malloc()
Detailed Academic Explanation:
malloc() is the correct answer to “In C, which function is used to allocate memory from the stack”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What happens if you attempt to free the same block of memory twice in C?
Correct Answer: Option A — It leads to undefined behavior
Detailed Academic Explanation:
It leads to undefined behavior is the correct answer to “What happens if you attempt to free the same block of memory twice in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the primary advantage of using dynamic memory allocation in C?
Correct Answer: Option A — Flexibility to allocate memory at runtime
Detailed Academic Explanation:
Flexibility to allocate memory at runtime is the correct answer to “What is the primary advantage of using dynamic memory allocation in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to allocate memory for a structure in C?
Correct Answer: Option A — malloc()
Detailed Academic Explanation:
malloc() is the correct answer to “Which function is used to allocate memory for a structure in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the difference between 'free' and 'delete' in C?
Correct Answer: Option A — 'free' is used for dynamic memory, 'delete' is used for static memory
Detailed Academic Explanation:
'free' is used for dynamic memory, 'delete' is used for static memory is the correct answer to “What is the difference between 'free' and 'delete' in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function is used to release all dynamically allocated memory in C?
Correct Answer: Option C — freeall()
Detailed Academic Explanation:
freeall() is the correct answer to “Which function is used to release all dynamically allocated memory in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In C, what is the purpose of the 'realloc' function?
Correct Answer: Option A — To change the size of a previously allocated block of memory
Detailed Academic Explanation:
To change the size of a previously allocated block of memory is the correct answer to “In C, what is the purpose of the 'realloc' function”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a memory fragment in C?
Correct Answer: Option A — Unused memory between allocated blocks
Detailed Academic Explanation:
Unused memory between allocated blocks is the correct answer to “What is a memory fragment in C”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
With every use of a memory allocation function, what function should be used to release allocated memory, which is no longer needed?
Correct Answer: Option E — free()
Detailed Academic Explanation:
free() is the correct answer to “With every use of a memory allocation function, what function should be used to release allocated memory, which is no longer needed”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Array is preferred over linked list for the implementation of . . . . . . . .
Correct Answer: Option C — Binary search
Detailed Academic Explanation:
Binary search is the correct answer to “Array is preferred over linked list for the implementation of . . . . . . . .”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The free() function frees the memory state pointed to by a pointer and returns . . . . . . . .
Correct Answer: Option C — no value
Detailed Academic Explanation:
no value is the correct answer to “The free() function frees the memory state pointed to by a pointer and returns . . . . . . . .”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
When the pointer is NULL, then the function realloc is equivalent to the function . . . . . . . .
Correct Answer: Option A — malloc
Detailed Academic Explanation:
malloc is the correct answer to “When the pointer is NULL, then the function realloc is equivalent to the function . . . . . . . .”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
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); }
Correct Answer: Option D — Error
Detailed Academic Explanation:
Error is the correct answer to “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); }”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C code? #include<stdio.h> #include<stdlib.h> void main() { char *p = calloc(100, 1); p = "welcome"; printf("%s\n", p); }
Correct Answer: Option B — welcome
Detailed Academic Explanation:
welcome is the correct answer to “What will be the output of the following C code? #include<stdio.h> #include<stdlib.h> void main() { char *p = calloc(100, 1); p = "welcome"; printf("%s\n", p); }”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is an example for non linear data type?
Correct Answer: Option A — Tree
Detailed Academic Explanation:
Tree is the correct answer to “Which of the following is an example for non linear data type”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Local variables are stored in an area called . . . . . . . .
Correct Answer: Option D — Stack
Detailed Academic Explanation:
Stack is the correct answer to “Local variables are stored in an area called . . . . . . . .”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
If the space in memory allocated by malloc is not sufficient, then an allocation fails and returns . . . . . . . .
Correct Answer: Option A — NULL pointer
Detailed Academic Explanation:
NULL pointer is the correct answer to “If the space in memory allocated by malloc is not sufficient, then an allocation fails and returns . . . . . . . .”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The following C code is an example of . . . . . . . . #include<stdio.h> #include<stdlib.h> #include<string.h> main() { char *p,*q; p=(char*)malloc(3*sizeof(char)); q=p; strcpy(p,"hello"); printf("p=%s",p); printf("q=%s",q); free(q); q=NULL; gets(p); gets(q); printf("%s",p); printf(“%s”,q); }
Correct Answer: Option B — Dangling pointer
Detailed Academic Explanation:
Dangling pointer is the correct answer to “The following C code is an example of . . . . . . . . #include<stdio.h> #include<stdlib.h> #include<string.h> main() { char *p,*q; p=(char*)malloc(3*sizeof(char)); q=p; strcpy(p,"hello"); printf("p=%s",p); printf("q=%s",q); free(q); q=NULL; gets(p); gets(q); printf("%s",p); printf(“%s”,q); }”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
If malloc() and calloc() are not type casted, the default return type is . . . . . . . .
Correct Answer: Option A — void*
Detailed Academic Explanation:
void* is the correct answer to “If malloc() and calloc() are not type casted, the default return type is . . . . . . . .”. This question is standard in competitive examination syllabi for Memory Allocation.
💡Key Conceptual Anchor:Memory Allocation
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.