Use the following lines of code to answer the next several questions. Assume the
ID: 3556933 • Letter: U
Question
Use the following lines of code to answer the next several questions. Assume the array b[ ] is loaded into memory at address location 2002 and an integer on this system has a size of 2, a float a size of 4 and a double a size of 8. You may use an answer more than once.
int b[ ] = { 0, 10, 20, 30 };
int *bPtr = b;
a. What is the ADDRESS of the value at location b[ 2 ] ?
b. What is the VALUE at location *bPtr ?
If I do this ++bPtr; once before the next two questions
c. What is the VALUE at location *bPtr ?
d. What will printf(
Explanation / Answer
a. 2006
As b[] is loaded into 2002 so it's starting address will be 2002 and thus, first elemnt is present at 2002. On incrementing, increments will happen by 2 at a time as it's an integer type array. So, b[0] is at 2002, b[1] at 2004 and thus, b[2] at 2006.
b. 0
Now, as bPtr is a integer pointer that points to 'b' so *bPtr points to the value at the address contained in bPtr which is address of 'b' i.e. 2002. Now, value at 2002 is 0.
c. 10
As the pointer is incremented and as it's an integer pointer, the address will be incremented by 2 and , thus, address becomes 2004. Now, as the value at 2004 is 10 so answer is 10.
d. 2004
It'll print the address contained in bPtr after 1 increment i.e. 2004 (as explained in previous question).