1. If int arr[5]; what type is arr?
(A) int array of size 5
(B) int pointer
(C) int reference
(D) int variable
2. If int arr[5]; then arr can be used as:
(A) Pointer to first element
(B) Reference to array
(C) Pointer to whole array
(D) None of these
3. What does *(arr + 2) represent?
(A) arr[0]
(B) arr[1]
(C) arr[2]
(D) arr[3]
4. Which of the following is correct to assign pointer to an array?
(A) int *ptr = arr[0];
(B) int *ptr = &arr;
(C) int ptr = arr;
(D) int *ptr = arr;
5. What is printed by this code?
int arr[3] = {10,20,30};
int *p = arr;
cout << *(p+1);
(A) 10
(B) 20
(C) 30
(D) Garbage
6. Which operator can be used to move pointer to next array element?
(A) &
(B) *
(C) ++
(D) >
7. What does p = arr + 2; point to?
(A) arr[0]
(B) arr[1]
(C) arr[3]
(D) arr[2]
8. Which is correct syntax to access array element using pointer?
(A) p[2]
(B) *(p + 2)
(C) Both A and B
(D) None of these
9. If int arr[5] and int *p = arr;, what is p – arr?
(A) 0
(B) 1
(C) 2
(D) Undefined
10. Which of the following is INCORRECT?
(A) arr[2] == *(arr + 2)
(B) arr++
(C) &arr == &arr[0]
(D) arr + 2 points to arr[2]
11. What happens if you access arr[5] for int arr[5]?
(A) Prints 0
(B) Prints garbage value
(C) Compiler error
(D) Undefined behavior
12. Pointer arithmetic is based on:
(A) Size of data type
(B) Value of pointer
(C) OS
(D) Compiler version
13. Which of the following is valid?
int arr[3] = {1,2,3};
int *p = arr;
(A) *(p + 1)
(B) p[2]
(C) *(arr + 2)
(D) All of the above
14. What does p[-1] mean?
(A) Invalid
(B) Access previous element
(C) Access first element
(D) Access last element
15. Which of the following correctly assigns pointer to 2D array row?
int arr[3][4];
(A) int *p = arr;
(B) int *p = arr[0];
(C) int *p = &arr[0][0];
(D) Both B and C
16. For int arr[2][3];, what is type of arr?
(A) int pointer
(B) int ()[3]
(C) int &
(D) int variable
17. What does *(*(arr+1)+2) represent in 2D array?
(A) arr[0][2]
(B) arr[1][2]
(C) arr[2][1]
(D) arr[2][2]
18. How do you assign pointer to the first element of a 2D array?
(A) int *p = arr;
(B) int (*p)[3] = arr;
(C) int *p = &arr[0][0];
(D) Both B and C
19. If int arr[5]; what is type of arr+1?
(A) int*
(B) int
(C) int&
(D) int**
20. Which of the following is valid to traverse an array using pointers?
(A) for(int *p = arr; p < arr+5; p++) cout << *p;
(B) for(int i=0; i<5; i++) cout << *(arr+i);
(C) Both A and B
(D) None
21. What does arr[2] = *(arr+2) illustrate?
(A) Pointer arithmetic
(B) Array and pointer equivalence
(C) Dereferencing pointer
(D) All of the above
22. What happens if you do arr = arr + 1;?
(A) Moves pointer
(B) Compiler error
(C) Works in C++
(D) Undefined behavior
23. What is output?
int arr[3] = {5,10,15};
int *p = arr;
cout << p[1];
(A) 5
(B) 10
(C) 15
(D) Garbage
24. How do you access element arr[i][j] using pointer?
(A) ((arr+i)+j)
(B) arr[i][j]
(C) Both A and B
(D) &arr[i][j]
25. Which of the following gives the address of a 2D array row?
(A) arr[i]
(B) &arr[i][0]
(C) Both A and B
(D) &arr
26. Which of the following is TRUE?
(A) Arrays are pointers
(B) Array name is constant pointer
(C) Array can be assigned to another array
(D) Arrays can be incremented
27. What is the output?
int arr[2][2] = {{1,2},{3,4}};
int (*p)[2] = arr;
cout << ((p+1)+0);
(A) 1
(B) 2
(C) 3
(D) 4
28. Which is correct pointer traversal for 2D array?
int arr[2][3];
(A) for(int i=0; i<2; i++) for(int j=0; j<3; j++) cout << ((arr+i)+j);
(B) int *p = &arr[0][0]; for(int i=0; i<6; i++) cout << *(p+i);
(C) Both A and B
(D) None
29. Which is valid to get size of array using pointer?
(A) sizeof(arr) / sizeof(arr[0])
(B) sizeof(p) / sizeof(p[0])
(C) Both A and B
(D) None
30. What does *arr give for int arr[5];?
(A) Address of array
(B) Value of first element
(C) Address of last element
(D) Garbage