Pointer arithmetic — C++ MCQs

19
Score: 0
Attempted: 0/19
1. If int arr[5] = {1,2,3,4,5}; and int *p = arr;, what does *(p+2) return?



2. Which operator is used to move a pointer to the next element of its type?



3. What is the output of the following?
int arr[3] = {10,20,30};
int *ptr = arr;
ptr++;
cout << *ptr;




4. If int *p points to an array element, what does p-1 do?



5. Pointer arithmetic depends on



6. What does the expression ptr + 3 do for int *ptr?



7. What is the output?
int arr[4] = {5,10,15,20};
int *p = arr;
cout << *(p+3);




8. Which of the following is valid pointer subtraction?



9. What is the result of subtracting two pointers pointing to the same array?



10. Can you perform ptr + 1.5 if ptr is an int pointer?



11. What does ptr++ do compared to ++ptr?



12. Pointer arithmetic is only valid for



13. If double arr[3] = {1.1,2.2,3.3}; and double *p = arr;, what is p + 1?



14. What happens if pointer goes outside array bounds?



15. How do you calculate the number of elements between two pointers p1 and p2 in the same array?



16. If int *p = &arr[0];, what does *(p + 2) equal?



17. Which pointer types allow pointer arithmetic?



18. What is the output?
int arr[5] = {1,2,3,4,5};
int *p = arr+4;
cout << *(p-2);




19. Which of the following is INCORRECT?



Contents Copyrights Reserved By T4Tutorials