C Pointers MCQ

In C, a pointer is a variable that stores the memory address of another variable. Using pointers, you can directly interact with memory locations, enabling various operations like dynamic memory allocation, array iterations, and function arguments passed by reference.

Let’s dive into the world of pointers in C and assess your comprehension with some multiple choice questions! Each question is followed by the correct answer and an explanation to help reinforce your knowledge.

1. What does a pointer store?

A) Actual value of a variable
B) Address of a variable
C) Both actual value and address
D) None of the above

Answer:

B) Address of a variable

Explanation:

A pointer stores the memory address of another variable.

2. Which operator is used to get the address of a variable?

a) *
b) &
c) ^
d) %

Answer:

b) &

Explanation:

The & operator is used to fetch the address of a variable.

3. Which operator is used to declare a pointer variable?

A) &
B) *
C) &&
D) %

Answer:

B) *

Explanation:

The * operator is used in the declaration of a pointer variable.

4. What does the following declaration mean?

int *ptr;
a) pointer to an int
b) double pointer
c) character pointer
d) pointer to a function

Answer:

a) pointer to an int

Explanation:

This declaration means that ptr is a pointer variable that can store the address of an int data type.

5. What is the output of the following code?

int a = 10;
int *p;
p = &a;
printf("%d", *p);
A) 10
B) Address of a
C) p
D) Address of p

Answer:

A) 10

Explanation:

The pointer p is assigned the address of a and *p dereferences the pointer, giving the value of a which is 10.

6. Which keyword is used to allocate dynamic memory in C?

a) new
b) malloc
c) alloc
d) dynalloc

Answer:

b) malloc

Explanation:

malloc stands for memory allocation and is used for dynamic memory allocation.

7. What will be the output of the following code segment?

int a = 5, *p = &a;
printf("%d", *p+2);
a) 2
b) 5
c) 7
d) None of the above

Answer:

c) 7

Explanation:

The value at pointer p is 5 (which is the value of a). So, *p + 2 = 5 + 2 = 7.

8. Which function is used to release dynamically allocated memory?

a) free
b) delete
c) remove
d) clear

Answer:

a) free

Explanation:

The free function is used to release memory that was previously allocated by malloc.

9. What is a NULL pointer?

a) Pointer pointing to some memory location
b) Pointer pointing to a function
c) A keyword in C
d) Pointer which is not pointing to any memory location

Answer:

d) Pointer which is not pointing to any memory location

Explanation:

A NULL pointer is a pointer that does not point to any memory location.

10. What is a dangling pointer?

a) A pointer pointing to an invalid memory location
b) A keyword in C
c) A pointer pointing to a valid memory location
d) A pointer which is NULL

Answer:

a) A pointer pointing to an invalid memory location

Explanation:

A dangling pointer is a pointer that points to a memory location that has been deleted or deallocated.


Understanding pointers is crucial in C programming as they provide a way to utilize the capabilities of the memory efficiently. We hope this quiz has enhanced your knowledge. Keep practicing and exploring more about pointers!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top