21
What is the maximum number of bytes that can be allocated using 'malloc' in C?
A)
It depends on the system and available memory
B)
2^16 bytes
C)
2^32 bytes
D)
2^64 bytes
Answer & Solution
Answer: Option
A
22
What is the difference between 'malloc' and 'calloc' in C?
A)
'malloc' allocates uninitialized memory, 'calloc' allocates and initializes to zero
B)
'malloc' allocates and initializes to zero, 'calloc' allocates uninitialized memory
C)
'malloc' is used for arrays, 'calloc' is used for single elements
D)
'malloc' allocates memory from the stack, 'calloc' allocates from the heap
Answer & Solution
Answer: Option
A
23
In C, which function is used to allocate memory from the stack?
A)
alloc()
B)
stackalloc()
C)
malloc()
D)
calloc()
Answer & Solution
Answer: Option
C
24
What happens if you attempt to free the same block of memory twice in C?
A)
It leads to undefined behavior
B)
The program terminates
C)
Memory is released, but the pointer remains valid
D)
Memory is leaked
Answer & Solution
Answer: Option
A
25
What is the primary advantage of using dynamic memory allocation in C?
A)
Flexibility to allocate memory at runtime
B)
Faster execution of programs
C)
Smaller memory footprint
D)
Elimination of memory leaks
Answer & Solution
Answer: Option
A
26
Which function is used to allocate memory for a structure in C?
A)
malloc()
B)
structurealloc()
C)
structalloc()
D)
calloc()
Answer & Solution
Answer: Option
A
27
What is the difference between 'free' and 'delete' in C?
A)
'free' is used for dynamic memory, 'delete' is used for static memory
B)
'free' is used for dynamic memory, 'delete' is used for freeing memory
C)
'free' is used for C, 'delete' is used for C++
D)
'free' is used for static memory, 'delete' is used for dynamic memory
Answer & Solution
Answer: Option
A
28
Which function is used to release all dynamically allocated memory in C?
A)
clearall()
B)
deallocateall()
C)
freeall()
D)
clearmemory()
Answer & Solution
Answer: Option
C
29
In C, what is the purpose of the 'realloc' function?
A)
To change the size of a previously allocated block of memory
B)
To allocate memory for a structure
C)
To copy memory
D)
To check for memory leaks
Answer & Solution
Answer: Option
A
30
What is a memory fragment in C?
A)
Unused memory between allocated blocks
B)
A type of data structure
C)
A reserved portion of memory
D)
A function to allocate memory
Answer & Solution
Answer: Option
A