Pointers and arrays — C++ MCQs

30
Score: 0
Attempted: 0/30
1. If int arr[5]; what type is arr?



2. If int arr[5]; then arr can be used as:



3. What does *(arr + 2) represent?



4. Which of the following is correct to assign pointer to an array?



5. What is printed by this code?
int arr[3] = {10,20,30};
int *p = arr;
cout << *(p+1);




6. Which operator can be used to move pointer to next array element?



7. What does p = arr + 2; point to?



8. Which is correct syntax to access array element using pointer?



9. If int arr[5] and int *p = arr;, what is p – arr?



10. Which of the following is INCORRECT?



11. What happens if you access arr[5] for int arr[5]?



12. Pointer arithmetic is based on:



13. Which of the following is valid?
int arr[3] = {1,2,3};
int *p = arr;




14. What does p[-1] mean?



15. Which of the following correctly assigns pointer to 2D array row?
int arr[3][4];




16. For int arr[2][3];, what is type of arr?



17. What does *(*(arr+1)+2) represent in 2D array?



18. How do you assign pointer to the first element of a 2D array?



19. If int arr[5]; what is type of arr+1?



20. Which of the following is valid to traverse an array using pointers?



21. What does arr[2] = *(arr+2) illustrate?



22. What happens if you do arr = arr + 1;?



23. What is output?
int arr[3] = {5,10,15};
int *p = arr;
cout << p[1];




24. How do you access element arr[i][j] using pointer?



25. Which of the following gives the address of a 2D array row?



26. Which of the following is TRUE?



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




28. Which is correct pointer traversal for 2D array?
int arr[2][3];




29. Which is valid to get size of array using pointer?



30. What does *arr give for int arr[5];?



Contents Copyrights Reserved By T4Tutorials