Pointers in C Programming MCQ Questions and Answers
1. Which of the following correctly declares a pointer to an integer in C?
A) int p;
B) int *p;
C) int &p;
D) int p*;
Answer: B
2. What is the output of the following code?
int x = 10;
int *p = &x;
printf(“%d”, *p);
A) Address of x
B) 10
C) Garbage value
D) Compilation error
Answer: B
3. If p is a pointer to an integer, what does p++ do?
A) Moves the pointer to the next byte
B) Moves the pointer to the next integer location
C) Increments the value pointed by p
D) Sets p to NULL
Answer: B
4. Which operator is used to get the value stored at the address a pointer is pointing to?
A) &
B) *
C) ->
D) %
Answer: B
5. What is the size of a pointer variable in a 64-bit system?
A) 2 bytes
B) 4 bytes
C) 8 bytes
D) Depends on data type
Answer: C
6. What will happen if you try to dereference a NULL pointer?
A) Program crashes or segmentation fault
B) Returns 0
C) Returns random value
D) Returns the pointer address
Answer: A
7. What is the output of the following code?
int a = 5;
int *p = &a;
printf(“%p”, p);
A) Value of a
B) Address of a
C) NULL
D) Compilation error
Answer: B
8. Which of the following is a pointer to a pointer?
A) int **p;
B) int *p;
C) int p;
D) int &p;
Answer: A
9. Which of the following statements about pointers is true?
A) Pointers can only point to integers
B) Pointers can store any memory address
C) Pointers cannot point to arrays
D) Pointers are always 4 bytes
Answer: B
10. What is the correct way to declare a constant pointer to an integer?
A) int *const p;
B) const int *p;
C) int const *p;
D) const int const *p;
Answer: A
11. What does the expression *(&x) return?
A) Address of x
B) Value of x
C) Garbage value
D) Compilation error
Answer: B
12. Which pointer type is used for dynamically allocated memory using malloc?
A) int
B) void*
C) char
D) float
Answer: B
13. Which of the following is true about void* pointer?
A) Can store address of any data type
B) Can be dereferenced directly
C) Must be typecast before dereferencing
D) Both A and C
Answer: D
14. Which of the following statements is correct about pointer arithmetic?
A) p + 1 moves pointer by 1 byte
B) p + 1 moves pointer by the size of the data type
C) p – 1 decreases pointer value by 1 byte
D) p++ decreases pointer value
Answer: B
15. What will the following code print?
int arr[3] = {10, 20, 30};
int *p = arr;
printf(“%d”, *(p+2));
A) 10
B) 20
C) 30
D) Garbage value
Answer: C
16. Which of the following can be used to prevent a pointer from modifying the value it points to?
A) int *p
B) const int *p
C) int *const p
D) int const *const p
Answer: B
17. What is the result of comparing two pointers using ==?
A) Compares values they point to
B) Compares addresses stored in pointers
C) Always returns false
D) Always returns true
Answer: B
18. Which of the following correctly represents pointer to an array?
A) int (*p)[5];
B) int *p[5];
C) int p*[5];
D) int &p[5];
Answer: A
19. What is the output of this code snippet?
char *str = “Hello”;
printf(“%c”, *str);
A) H
B) e
C) Hello
D) Compilation error
Answer: A
20. Which statement is true about function pointers?
A) They can be used to call functions indirectly
B) They can point to variables
C) They cannot be passed as arguments
D) They are always of type void*
Answer: A
21. What is the type of &ptr if ptr is int*?
A) int
B) int*
C) int**
D) void*
Answer: C
22. Which of the following is used to allocate memory for an array of integers?
A) malloc(sizeof(int));
B) malloc(10);
C) malloc(10 * sizeof(int));
D) malloc(int[10]);
Answer: C
23. What is wrong with the following code?
int *p;
*p = 10;
A) Syntax error
B) Dereferencing uninitialized pointer
C) Type mismatch
D) Nothing wrong
Answer: B
24. Which of the following is correct for pointer to a function returning int?
A) int *func();
B) int (*func)();
C) int *(*func)();
D) int (*func)[];
Answer: B
25. Which of the following is true for null pointers?
A) Always points to a valid memory
B) Can be dereferenced safely
C) Used to indicate that pointer points to nothing
D) None of the above
Answer: C
26. What is the result of the following code?
int x = 5;
int *p = &x;
*p = *p + 10;
printf(“%d”, x);
A) 5
B) 10
C) 15
D) Garbage value
Answer: C
27. Which of the following is the correct way to pass a pointer to a function?
A) void func(int p)
B) void func(int *p)
C) void func(&p)
D) void func(*p)
Answer: B
28. What is the type of arr in the following declaration?
int arr[10];
A) int*
B) int[10]
C) int**
D) void*
Answer: B
29. How do you declare a pointer that cannot change the address it points to, but can modify the value?
A) int *const p;
B) const int *p;
C) int const *p;
D) const int *const p;
Answer: A
30. What is the output of the following code?
int a = 10, b = 20;
int *p = &a, *q = &b;
p = q;
printf(“%d”, *p);
A) 10
B) 20
C) Garbage value
D) Compilation error
Answer: B
31. Which of the following correctly frees dynamically allocated memory?
A) delete(p);
B) free(p);
C) release(p);
D) remove(p);
Answer: B
32. Which statement is true about sizeof(pointer)?
A) Returns size of data pointed to
B) Returns size of pointer itself
C) Returns size of memory allocated dynamically
D) Always returns 4
Answer: B
33. What is the value of p – q if p and q are pointers pointing to elements of the same array?
A) Number of bytes between them
B) Difference in indices
C) Always 1
D) Cannot be calculated
Answer: B
34. Which of the following is invalid pointer declaration?
A) int *p;
B) char *ch;
C) int **p;
D) int p*;
Answer: D
35. Which of the following statements is true about pointer to a structure?
A) Cannot be used to access members
B) Can be used with -> operator
C) Must be dereferenced using *
D) Cannot point to dynamically allocated memory
Answer: B
36. What will the following code print?
int arr[] = {1, 2, 3};
int *p = arr;
printf(“%d”, *p++);
A) 1
B) 2
C) 3
D) Compilation error
Answer: A
37. What is the correct syntax to declare an array of pointers to integers?
A) int *arr[10];
B) int (*arr)[10];
C) int arr*[];
D) int arr[10]*;
Answer: A
38. What is the type of pointer returned by malloc in C?
A) int*
B) char*
C) void*
D) float*
Answer: C
39. What is the output of the following code?
char c = ‘A’;
char *p = &c;
printf(“%c”, *p);
A) A
B) &
C) Garbage
D) Compilation error
Answer: A
40. What happens when a pointer goes out of scope?
A) It is automatically freed
B) The memory it points to is freed
C) The pointer variable is destroyed, memory remains intact
D) Causes segmentation fault
Answer: C
41. Which of the following is true about dangling pointers?
A) They point to valid memory
B) They point to freed memory
C) They are initialized to NULL
D) They cannot be created in C
Answer: B
42. Which of the following is used to allocate memory for a single integer dynamically?
A) malloc(sizeof(int))
B) malloc(1)
C) malloc(4)
D) malloc(int)
Answer: A
43. What is the output of the following snippet?
int x = 10;
int *p = &x;
printf(“%u”, (unsigned int)p);
A) Value of x
B) Address of x
C) NULL
D) Garbage value
Answer: B
44. Which statement is correct regarding pointers and arrays?
A) Array name can be used as a pointer
B) Arrays cannot be passed to functions using pointers
C) Pointer cannot point to array elements
D) Arrays are always dynamically allocated
Answer: A
45. Which of the following cannot be a pointer?
A) int
B) float
C) void
D) struct
Answer: C
46. Which of the following is true for pointer to function?
A) Must point to void type
B) Can be called using (*func)() syntax
C) Cannot be passed as argument
D) Always returns int
Answer: B
47. Which of the following is a dangling pointer?
A) int *p = NULL;
B) int *p = malloc(sizeof(int)); free(p);
C) int *p; p = &x;
D) int x = 10; int *p = &x;
Answer: B
48. How do you access the second element of an array using a pointer?
A) *(p+1)
B) *(p-1)
C) *p
D) p[0]
Answer: A
49. Which of the following correctly declares a pointer to a function taking int and returning void?
A) void *func(int);
B) void (*func)(int);
C) void (*func(int));
D) int (*func)(void);
Answer: B
50. Which of the following is true about pointer and structures in C?
A) Structure cannot have pointer members
B) Pointer to structure must be dereferenced using ->
C) Pointer cannot be used with . operator
D) Pointer to structure is always of type void*
Answer: B
51. Which of the following is true about const pointer?
A) Pointer cannot change address it points to
B) Value pointed by pointer cannot be changed
C) Pointer and value both cannot change
D) None of the above
Answer: A
52. Which of the following expressions gives the address of a pointer variable p?
A) *p
B) &p
C) p++
D) *(&p)
Answer: B
53. Which of the following is correct to allocate memory for 10 integers?
A) int *p = malloc(10);
B) int *p = malloc(10 * sizeof(int));
C) int *p = malloc(sizeof(int));
D) int *p = malloc(1);
Answer: B
54. Which of the following is true about null pointers?
A) Always points to 0
B) Can be dereferenced
C) Indicates pointer points to nothing
D) Same as uninitialized pointer
Answer: C
55. What is the output of this code?
int a = 5;
int *p = &a;
printf(“%d”, a + *p);
A) 5
B) 10
C) 25
D) Compilation error
Answer: B
56. Which of the following is correct declaration of pointer to pointer to int?
A) int p**;
B) int **p;
C) int *p*;
D) int &*p;
Answer: B
57. What is the output of the following snippet?
int arr[] = {10, 20, 30};
int *p = arr;
printf(“%d”, *(p+1));
A) 10
B) 20
C) 30
D) Garbage
Answer: B
58. Which operator is used to access members of a structure through pointer?
A) .
B) ->
C) *
D) &
Answer: B
59. Which of the following statements is correct about dangling pointer?
A) It points to freed memory
B) Always initialized to NULL
C) Can be used safely
D) Points to global variables
Answer: A
60. What is the output of this code?
int x = 10;
int *p = &x;
*p += 5;
printf(“%d”, x);
A) 10
B) 5
C) 15
D) Garbage
Answer: C
61. What is the type of pointer returned by calloc?
A) int*
B) void*
C) char*
D) float*
Answer: B
62. Which of the following is correct about pointer arithmetic?
A) Can add two pointers
B) Can subtract two pointers pointing to same array
C) Can multiply pointer by integer
D) Can divide pointer by integer
Answer: B
63. Which of the following is a correct way to initialize a pointer to NULL?
A) int *p = 0;
B) int *p = NULL;
C) int *p = ‘\0’;
D) Both A and B
Answer: D
64. What is the output of the following code?
int x = 5;
int *p = &x;
printf(“%p”, (void*)p);
A) Address of x
B) Value of x
C) 5
D) NULL
Answer: A
65. Which of the following is correct syntax to pass pointer to a function?
A) void func(int *p);
B) void func(int &p);
C) void func(*p);
D) void func(&p);
Answer: A
66. Which of the following statements about function pointers is correct?
A) Can be used to call a function indirectly
B) Cannot store address of a function
C) Cannot be passed to another function
D) Always returns void
Answer: A
67. Which of the following statements about void* pointer is true?
A) Can point to any data type
B) Cannot be dereferenced directly
C) Must be typecast before dereferencing
D) All of the above
Answer: D
68. What does the expression *p++ mean?
A) Increment pointer, then dereference old value
B) Dereference pointer, then increment pointer
C) Dereference pointer twice
D) Invalid expression
Answer: B
69. Which of the following is correct declaration of a pointer to an array of 5 integers?
A) int *arr[5];
B) int (*arr)[5];
C) int arr*[5];
D) int &arr[5];
Answer: B
70. What will the following code print?
char *str = “UGC”;
printf(“%c”, *(str+1));
A) U
B) G
C) C
D) Garbage
Answer: B
71. Which of the following is true about pointers and arrays?
A) Array name is a constant pointer
B) Arrays cannot be passed to functions
C) Pointer cannot point to array elements
D) Pointer arithmetic is invalid with arrays
Answer: A
72. Which of the following is used to free memory allocated dynamically?
A) free()
B) delete
C) remove()
D) release()
Answer: A
73. Which of the following is true for pointer to pointer?
A) Can store address of another pointer
B) Can store address of an integer
C) Cannot point to NULL
D) Cannot be dereferenced
Answer: A
74. What is the output of this code?
int x = 10;
int *p = &x;
int **q = &p;
printf(“%d”, **q);
A) Address of x
B) 10
C) Address of p
D) Garbage
Answer: B
75. Which of the following is correct about pointer typecasting?
A) A pointer can be typecast to any other pointer type
B) Pointer typecasting is invalid
C) Pointer cannot be typecast to void*
D) Pointer arithmetic is impossible after typecasting
Answer: A
76. Which of the following is true for an uninitialized pointer?
A) Always NULL
B) May contain garbage address
C) Always points to zero
D) Safe to dereference
Answer: B
77. Which of the following is the correct way to declare a constant pointer to constant int?
A) const int *p;
B) int *const p;
C) const int *const p;
D) int const p*;
Answer: C
78. Which of the following is a dangling pointer scenario?
A) Pointer points to local variable after function ends
B) Pointer initialized to NULL
C) Pointer to global variable
D) Pointer pointing to static memory
Answer: A
79. Which of the following is the correct syntax for pointer to function returning int?
A) int *func();
B) int (*func)();
C) int func*();
D) int &func();
Answer: B
80. What is the output of:
int arr[3] = {1,2,3};
int *p = arr;
printf(“%d”, *(p+0));
A) 0
B) 1
C) 2
D) 3
Answer: B
81. Which of the following is true for pointer increment p++?
A) Adds 1 to pointer value in bytes
B) Adds size of data type pointed to
C) Decrements pointer value
D) Sets pointer to NULL
Answer: B
82. What is the output of:
int a = 5, b = 10;
int *p = &a, *q = &b;
printf(“%d”, *p + *q);
A) 5
B) 10
C) 15
D) Compilation error
Answer: C
83. Which of the following correctly declares an array of pointers to characters?
A) char *arr[5];
B) char (*arr)[5];
C) char arr*[];
D) char &arr[5];
Answer: A
84. What happens when you dereference a void pointer without typecasting?
A) Works fine
B) Compilation error
C) Runtime error
D) Returns NULL
Answer: B
85. What is the output of:
char *s = “CSE”;
printf(“%c”, *s);
A) C
B) S
C) E
D) Garbage
Answer: A
86. Which of the following statements is correct?
A) Pointers cannot point to functions
B) Pointer to function can be passed as argument
C) Function pointer cannot be dereferenced
D) Function pointers are always void*
Answer: B
87. Which of the following is true for pointer to structure?
A) Use . to access members
B) Use -> to access members
C) Cannot access members
D) Must use typecasting to int*
Answer: B
88. Which of the following is a correct way to declare a pointer to a 2D array?
A) int *p[5][5];
B) int (*p)[5];
C) int p*[][5];
D) int **p[5];
Answer: B
89. Which of the following statements about NULL pointer is correct?
A) Points to zero
B) Can be dereferenced
C) Always contains 1
D) Indicates pointer points to valid memory
Answer: A
90. Which of the following is true about free() function?
A) Frees dynamically allocated memory
B) Can free statically allocated variables
C) Frees global variables
D) Deletes pointer variable itself
Answer: A
91. What is the output of:
int x = 10;
int *p = &x;
int **q = &p;
printf(“%d”, *p);
A) Address of x
B) 10
C) Address of p
D) Garbage
Answer: B
92. Which of the following statements is true about pointer to pointer?
A) Points to integer only
B) Can store address of another pointer
C) Cannot point to NULL
D) Cannot be dereferenced
Answer: B
93. What is the output of:
int arr[3] = {10,20,30};
int *p = arr;
printf(“%d”, *(p+2));
A) 10
B) 20
C) 30
D) Garbage
Answer: C
94. Which of the following statements is correct about const int *p?
A) Pointer cannot change address
B) Value pointed by pointer cannot be changed
C) Both pointer and value are constant
D) Pointer is NULL
Answer: B
95. Which of the following correctly frees dynamically allocated memory and avoids dangling pointer?
A) free(p); p=NULL;
B) free(p);
C) p=NULL;
D) delete p;
Answer: A
96. Which of the following is true for *ptr = *ptr + 1?
A) Increments pointer
B) Increments value pointed to
C) Decrements pointer
D) Causes error
Answer: B
97. What is the output of:
int x = 1;
int *p = &x;
*p += 2;
printf(“%d”, x);
A) 1
B) 2
C) 3
D) 0
Answer: C
98. Which of the following is correct for passing array to a function?
A) Pass array name as pointer
B) Pass array using &
C) Pass array using *
D) Cannot pass array
Answer: A
99. Which of the following is true about function pointer?
A) Can store address of variable
B) Can be used to call function indirectly
C) Cannot point to void functions
D) Always points to int functions
Answer: B
100. Which of the following correctly represents pointer arithmetic to access array element?
A) *(arr+i)
B) *(arr-i)
C) arr[i]*
D) *arr[i]
Answer: A
