Question 31
Consider 'int arr[5] = {10, 20, 30, 40, 50};'. What is the value of '*(arr + 3)'?
Detailed Solution
Pointer arithmetic 'arr + 3' points to index 3 (4th element). Dereferencing it with *(arr + 3) gives 40.
Consider 'int arr[5] = {10, 20, 30, 40, 50};'. What is the value of '*(arr + 3)'?
Pointer arithmetic 'arr + 3' points to index 3 (4th element). Dereferencing it with *(arr + 3) gives 40.
If 'arr' is a 1D array of integers, which of the following is equivalent to 'arr[i]'?
By C specification, array subscripting arr[i] is defined as *(arr + i).
Given 'int arr[3][4];', assuming base address is 2000 and int is 4 bytes, what is the address of 'arr[2][1]' in row-major order?
Offset = (row * num_cols + col) * sizeof(int) = (2 * 4 + 1) * 4 = 9 * 4 = 36 bytes. Address = 2000 + 36 = 2036.
What is the type of variable 'p' declared as 'int (*p)[5];'?
Parentheses (*p) bind precedence to the pointer first, declaring 'p' as a pointer to an array of 5 ints.
What is the type of variable 'p' declared as 'int *p[5];'?
Subscript [] has higher precedence than *, making 'p' an array of 5 pointers to integers.