Complete the code to declare a pointer to an integer.
int* [1];The code declares a pointer variable named ptr that can hold the address of an integer.
Complete the code to assign the address of variable num to pointer ptr.
ptr = [1]num;* instead of the address-of operator.&& which is incorrect here.The ampersand & operator gives the address of the variable num, which is assigned to the pointer ptr.
Fix the error in the code to access the first element of the array using a pointer.
int arr[3] = {1, 2, 3}; int* ptr = arr; int first = [1]ptr;
& instead of dereference.-> which is for pointers to structs or classes.The dereference operator * is used to access the value pointed to by ptr, which is the first element of the array.
Fill both blanks to create a pointer that points to the third element of the array.
int arr[5] = {10, 20, 30, 40, 50}; int* ptr = [1] + [2];
&arr which is a pointer to the whole array, not the first element.The pointer ptr is set to point to the element at index 2 (third element) by adding 2 to the array name arr.
Fill all three blanks to create a pointer to an array element and access its value.
int nums[4] = {5, 10, 15, 20}; int* ptr = [1] + [2]; int val = *[3];
nums + 2 for the first blank which is incorrect here.nums instead of the pointer ptr.The pointer ptr points to the second element (index 1) of the array nums. Then *ptr accesses the value at that position.