Q. What does the 'malloc' function do in C?
-
A.
Allocates memory on the stack
-
B.
Allocates memory on the heap
-
C.
Frees allocated memory
-
D.
Initializes a pointer
Solution
'malloc' allocates a specified number of bytes of memory on the heap and returns a pointer to the allocated memory.
Correct Answer:
B
— Allocates memory on the heap
Learn More →
Q. What does the term 'memory leak' refer to?
-
A.
Not freeing allocated memory
-
B.
Accessing uninitialized memory
-
C.
Using too much stack space
-
D.
Overwriting memory
Solution
A memory leak occurs when allocated memory is not freed, leading to wasted memory resources.
Correct Answer:
A
— Not freeing allocated memory
Learn More →
Q. What is a dangling pointer?
-
A.
A pointer that points to a valid memory location
-
B.
A pointer that points to a memory location that has been freed
-
C.
A pointer that is not initialized
-
D.
A pointer that points to itself
Solution
A dangling pointer is one that points to a memory location that has been freed, leading to undefined behavior if accessed.
Correct Answer:
B
— A pointer that points to a memory location that has been freed
Learn More →
Q. What is a pointer in programming?
-
A.
A variable that stores a memory address
-
B.
A type of loop
-
C.
A function that returns a value
-
D.
A data structure
Solution
A pointer is a variable that stores the memory address of another variable.
Correct Answer:
A
— A variable that stores a memory address
Learn More →
Q. What is the purpose of the 'free' function in C?
-
A.
To allocate memory
-
B.
To release allocated memory
-
C.
To initialize a pointer
-
D.
To check memory usage
Solution
'free' is used to release memory that was previously allocated with 'malloc' or similar functions.
Correct Answer:
B
— To release allocated memory
Learn More →
Q. What is the result of dereferencing a null pointer?
-
A.
It returns zero
-
B.
It causes a segmentation fault
-
C.
It returns a random value
-
D.
It is valid and returns a pointer
Solution
Dereferencing a null pointer causes a segmentation fault, as it attempts to access an invalid memory location.
Correct Answer:
B
— It causes a segmentation fault
Learn More →
Q. What is the size of a pointer on a 64-bit system?
-
A.
2 bytes
-
B.
4 bytes
-
C.
8 bytes
-
D.
16 bytes
Solution
On a 64-bit system, the size of a pointer is typically 8 bytes, as it needs to store a 64-bit memory address.
Correct Answer:
C
— 8 bytes
Learn More →
Q. Which of the following is true about pointers?
-
A.
Pointers can only point to integers
-
B.
Pointers can point to any data type
-
C.
Pointers cannot be reassigned
-
D.
Pointers are always initialized to zero
Solution
Pointers can point to any data type, allowing for flexible memory management.
Correct Answer:
B
— Pointers can point to any data type
Learn More →
Q. Which operator is used to access the value at the address stored in a pointer?
Solution
The '*' operator is used to dereference a pointer and access the value at the address it points to.
Correct Answer:
B
— *
Learn More →
Showing 1 to 9 of 9 (1 Pages)