5.5.3 - Array of Pointers.
41. What is the correct syntax for declaring a pointer to an array in C?
- (A) int *p[5];
- (B) int (*p)[5];
- (C) int p[5];
- (D) int p[5][5];
(B) int (*p)[5];
42. Which of the following is a valid way to initialize a pointer to the first element of an array?
- (A) int *p = array[0];
- (B) int *p = &array[0];
- (C) int p = array[0];
- (D) int *p = &array;
(B) int *p = &array[0];
43. What does the expression *(p + 1) represent in pointer arithmetic when p points to the first element of an array?
- (A) The first element
- (B) The second element
- (C) The third element
- (D) The last element
(B) The second element
44. Which of the following statements about arrays and pointers is true?
- (A) Arrays are pointers
- (B) Arrays and pointers are the same
- (C) Array names are constants and cannot be changed
- (D) Pointers can be incremented, but arrays cannot
(C) Array names are constants and cannot be changed
45. Which operator is used to get the address of the first element of an array?
(B) &
46. What is the output of the following code?
int arr[] = {1, 2, 3};
int *p = arr;
printf("%d", *(p + 1));
- (A) 1
- (B) 2
- (C) 3
- (D) Error
(B) 2
47. Which of the following operations is invalid for array names?
- (A) Incrementing the array name
- (B) Getting the address of the array name
- (C) Passing the array to a function
- (D) Accessing array elements using a pointer
(A) Incrementing the array name
48. Which of the following declares a pointer to a function?
- (A) int (*p)(int, int);
- (B) int p(int, int);
- (C) int *p(int, int);
- (D) int p*(int, int);
(A) int (*p)(int, int);
49. If int arr[5] and int *p = arr;, which expression correctly accesses the third element of the array?
- (A) *(p + 2)
- (B) p[3]
- (C) *(p + 3)
- (D) p[2]
(A) *(p + 2)
50. What is the output of the following code?
int arr[] = {10, 20, 30, 40};
int *p = arr + 2;
printf("%d", *p);
- (A) 10
- (B) 20
- (C) 30
- (D) 40
(C) 30
51. Which statement correctly passes an array to a function?
- (A) func(&array);
- (B) func(*array);
- (C) func(array);
- (D) func(array[0]);
(C) func(array);
52. In pointer arithmetic, what is the result of subtracting two pointers?
- (A) A pointer
- (B) An integer representing the difference in elements
- (C) The memory address difference
- (D) An error
(B) An integer representing the difference in elements
53. What is the size of a pointer on a 64-bit machine?
- (A) 2 bytes
- (B) 4 bytes
- (C) 8 bytes
- (D) 16 bytes
(C) 8 bytes
54. Which of the following is NOT true about pointers and arrays in C?
- (A) A pointer can be used to traverse an array
- (B) An array name can be assigned to a pointer
- (C) Arrays can be resized using pointers
- (D) Pointer arithmetic can be performed on an array
(C) Arrays can be resized using pointers
55. Which of the following correctly accesses the value at the second index of the array using pointer notation?
- (A) *(array + 2)
- (B) *(array + 1)
- (C) array[2]
- (D) array[1]
(A) *(array + 2)
56. Which of the following is a valid way to declare a pointer to an array of integers?
- (A) int *arr[5];
- (B) int (*arr)[5];
- (C) int arr*;
- (D) int *arr[];
(B) int (*arr)[5];
57. Which of the following is true about the relationship between arrays and pointers?
- (A) Arrays can be resized using pointers
- (B) Array elements can be accessed using pointers
- (C) Array names are mutable
- (D) Arrays are dynamically allocated by default
(B) Array elements can be accessed using pointers
58. In C, how can you pass an entire array to a function?
- (A) By passing the array name
- (B) By passing a pointer to the first element
- (C) Both A and B
- (D) None of the above
(C) Both A and B
59. What is the difference between array and &array[0] in C?
- (A) They are the same
- (B) array points to the entire array, &array[0] points to the first element
- (C) array gives the address of the array, &array[0] gives the address of the first element
- (D) &array[0] points to the entire array
(B) array points to the entire array, &array[0] points to the first element
60. What is the output of the following code?
int arr[] = {5, 10, 15};
int *p = arr;
p += 2;
printf("%d", *p);
- (A) 5
- (B) 10
- (C) 15
- (D) 20
(C) 15
61. What does the following code snippet do? *pArray1++ = 1;
- (A) Assigns 1 to the current element pointed by pArray1 and increments the pointer.
- (B) Assigns 1 to the current element without incrementing the pointer.
- (C) Increments the pointer and then assigns 1 to the element.
- (D) Assigns 1 to the next element pointed by pArray1.
(A) Assigns 1 to the current element pointed by pArray1 and increments the pointer.
62. What does the expression *(pArray++) do?
- (A) Increments the value stored at the pointer.
- (B) Dereferences the pointer and then increments the pointer.
- (C) Increments the pointer first, then dereferences it.
- (D) Both increments and dereferences the pointer simultaneously.
(B) Dereferences the pointer and then increments the pointer.
63. What happens if you remove parentheses from the expression *(pArray2 + i)?
- (A) The code will produce an error.
- (B) It will behave the same as before.
- (C) It will cause incorrect pointer arithmetic.
- (D) It will change the memory address calculation.
(D) It will change the memory address calculation.
64. Which of the following is the correct way to declare an array in C?
- (A) int array[5];
- (B) int array{5};
- (C) array int[5];
- (D) int [5]array;
(A) int array[5];
65. What is the result of the expression (*pArray)++?
- (A) It increments the pointer value.
- (B) It increments the value stored at the memory location pointed by pArray.
- (C) It increments both the value and the pointer.
- (D) It increments the value before dereferencing the pointer.
(B) It increments the value stored at the memory location pointed by pArray.
66. What is the difference between *pArray++ and ++*pArray?
- (A) Both expressions increment the value at pArray.
- (B) *pArray++ increments the pointer, and ++*pArray increments the value at the pointer.
- (C) ++*pArray increments the pointer, and *pArray++ increments the value at the pointer.
- (D) Both expressions increment the pointer.
(B) *pArray++ increments the pointer, and ++*pArray increments the value at the pointer.
67. Which of the following statements is true about pointers in C?
- (A) Pointers can only point to integer values.
- (B) A pointer can store the address of another pointer.
- (C) Pointers cannot be dereferenced.
- (D) Pointers can point to different data types, but not arrays.
(B) A pointer can store the address of another pointer.
68. What is the value of array[0] after executing the code int array[3] = {1, 2, 3};?
- (A) 0
- (B) 1
- (C) 2
- (D) Undefined
(B) 1
69. Which of the following is a valid use of a pointer?
- (A) Accessing array elements
- (B) Dynamic memory allocation
- (C) Function parameters
- (D) All of the above
(D) All of the above
70. What is the output of the following code? printf("%p", &array[0]);
- (A) Prints the address of the first element of the array.
- (B) Prints the value of the first element of the array.
- (C) Prints the address of the entire array.
- (D) Prints the memory size of the array.
(A) Prints the address of the first element of the array.
71. What does arrayName represent in C when dealing with arrays?
- (A) The number of elements in the array
- (B) The address of the first element
- (C) The address of the last element
- (D) A constant pointer to the entire array
(B) The address of the first element
72. Which function is commonly used for dynamic memory allocation in C?
- (A) malloc()
- (B) scanf()
- (C) printf()
- (D) free()
(A) malloc()
73. What is the purpose of free() in C?
- (A) It deallocates dynamically allocated memory.
- (B) It creates a new dynamic array.
- (C) It prints a pointer value.
- (D) It reallocates the memory block.
(A) It deallocates dynamically allocated memory.
74. In C, how is a pointer incremented to traverse an array?
- (A) By adding 1 to the pointer value.
- (B) By multiplying the pointer value by the array size.
- (C) By adding the array size to the pointer.
- (D) By dividing the pointer by the array length.
(A) By adding 1 to the pointer value.
75. Which operator is used to dereference a pointer?
- (A) &
- (B) *
- (C) ++
- (D) --
(B) *
76. What will happen if you increment an array name directly in C?
- (A) The pointer will move to the next element.
- (B) It will cause a compile-time error.
- (C) The array size will change.
- (D) The value of the first element will increase.
(B) It will cause a compile-time error.
77. Which function is used to dynamically allocate an array?
- (A) malloc()
- (B) calloc()
- (C) realloc()
- (D) All of the above
(B) calloc()
78. What is the purpose of *(pArray++) in the context of pointer arithmetic?
- (A) Increment the pointer and dereference it simultaneously.
- (B) Dereference the pointer and increment it afterwards.
- (C) Increment the value at the pointer location.
- (D) Move to the next element of the array.
(B) Dereference the pointer and increment it afterwards.
79. What is the result of the statement pArray1++?
- (A) The value at the current pointer is incremented.
- (B) The pointer is moved to the next element.
- (C) The pointer is reset to the first element.
- (D) The array size is incremented.
(B) The pointer is moved to the next element.
80. In C, how can you initialize an array and pointer at the same time?
- (A) int array[5] = {1, 2, 3, 4, 5}; int *pArray = array;
- (B) int array[5] = {1, 2, 3, 4, 5}; int pArray = array[0];
- (C) int array[5] = {1, 2, 3, 4, 5}; array[0] = pArray;
- (D) int array[5] = {1, 2, 3, 4, 5}; int *pArray = &array[5];
(A) int array[5] = {1, 2, 3, 4, 5}; int *pArray = array;