Complete the code to access the next element using pointer arithmetic.
int arr[] = {10, 20, 30};
int *ptr = arr;
int value = *(ptr [1] 1);Adding 1 to the pointer moves it to the next integer element in the array.
Complete the code to calculate the number of elements between two pointers.
int arr[] = {5, 10, 15, 20};
int *start = &arr[0];
int *end = &arr[3];
int diff = end [1] start;Subtracting two pointers gives the number of elements between them.
Fix the error in the pointer arithmetic expression to access the third element.
int nums[] = {1, 2, 3, 4};
int *p = nums;
int val = *(p[1] 2);To access the third element, add 2 to the pointer before dereferencing.
Fill both blanks to create a pointer that points to the second element and then access it.
int data[] = {7, 14, 21};
int *ptr = data [1] 1;
int val = [2]ptr;Adding 1 moves the pointer to the second element. Dereferencing with '*' accesses the value.
Fill all three blanks to create a pointer to the last element, subtract 2 to get the first, and dereference it.
int vals[] = {3, 6, 9};
int *p = vals [1] 2;
int *q = p [2] 2;
int result = [3]q;Adding 2 moves pointer to last element, subtracting 2 moves back to first, dereferencing with '*' gets the value.