Read the Pointers and Array handout and try your best to fin

Read the Pointers and Array handout and try your best to finish the following exercise. Evaluate the following expression. ip is declared and has been given the value as follows. int *ip, a[6]; ip = &a;[theta]; Variable Name/address memory value

Solution

ip : ip is pointer, and variable should return the address it is pointing to i.e. 5164
&ip : referencing a variable returns the address of that variable, ie. 5208 in this case
*ip : Using aestrik (*), dereferences the pointer, and return the value at memory address the pointer is pointing to. ip points to memory address 5164, so *ip will return value store at 5164 which in this case is : 5160
a : a is array and it returns the address of first element in the array i.e. 5164
ip+1 : Adding 1 to ip doesn\'t add 1 to memory address stored in ip but it first looks what type of pointer it is. For example, if it points to integer, ip+1 should add 4 to memory addresses it stores. In this case, ip points to 5164, ip+1, should point to 5168
*(ip+1) : Dereferencing operation, return value at 5168 i.e. 5162
*ip + 1 : Adding 1 to (value stored at memory address pointed by ip) , i.e. 5161
ip[1] : It is similar to *(ip+1), thus 5162
&ip[1] + 1 : &ip[1] refers to (memory address of ip + 4bytes), adding 1 to it is equivalent to add 1 to a pointer. Thus it should be 5164+8= 5172
*(ip+2) + 2 : It is equivalent to ip[2] + 2 i.e. 5164+2 = 5166

 Read the Pointers and Array handout and try your best to finish the following exercise. Evaluate the following expression. ip is declared and has been given th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site