Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The table below lists a set of C variables, their address, and their values. For

ID: 3739815 • Letter: T

Question

The table below lists a set of C variables, their address, and their values. For each expression below, show what it evaluates to.

Assume that an expression evaluating to true always has the value 1.

Also, assume that char and int are the same size and both take up one location in LC-3 memory.

Also, assume the expressions are evaluated independently without updates.

In the case of arrays, the initial values should be interpreted with the same meaning as C array initializers.

Hint: If a pointer is used to dereference a memory location either using array notation or pointer notation, the resulting type of the expression must match the base type of the pointer, regardless of what might actually be in memory.

Variable

Base Address

Value(s)

int a

0xFF00

3

int b

0xFF01

-20

char c

0xFF02

‘d’

int* d

0xFF03

0xFF00

int e[10]

0xFF04

{1,1,2,3,5,8,13,21,34,0}

int** f

0x3104

0xFF03

char str[15]

0x3105

“Fake news!”



Variable

Base Address

Value(s)

int a

0xFF00

3

int b

0xFF01

-20

char c

0xFF02

‘d’

int* d

0xFF03

0xFF00

int e[10]

0xFF04

{1,1,2,3,5,8,13,21,34,0}

int** f

0x3104

0xFF03

char str[15]

0x3105

“Fake news!”

Expression (Type) Value d [3] e [5] f) [10] E [101 str fe [4]1 str [1] d+a & f

Explanation / Answer

1) *d

This will dereference the memory location that d is pointing to. i.e the variable a. Hence, *d will output the value held by a, i.e 3.
So, Value = 3, Type = int

2) d[3]

This will reference to the value at address held by d + 3 memory slots. i.e 0xFF00 + 3 = 0xFF03.
And the value held at this location is 0xFF00. Its an integer pointer.
So, Value = 0xFF00, Type = int pointer

3) a *b

This will simply multiply the values of a and b. So, (3)x(-20) = -60.
So, Value = -60, Type = int

4) e[a+1]

This will give the value of element at the (a+1) + 1 th position in the array e[].
So, a+1+1 = 5th element in e[], which is 5.
So, Value = 5, Type = int

5) e[5]

This will give the value of element at the 5+1 th position in the array e[].
So, 5+1 = 6th element in e[], which is 8.
So, value = 8, Type = int.

6) (*f)[10]

This gives the value of the memory space which is 10 blocks away from the address referenced by *f.
So, 0xFF03 + 10, which references to the 9th element in e. So, (*f)[10] = e[9-1] = e[8] = 21.
So, value = 21, Type = int.

7)*d + 1

This gives the value pointed by d and adds +1 to it. So, value pointed by d is the value at a, i.e. 3
So, *d + 1 = 3+1 = 4
So, value = 4, type = int

8) f[10]

This gives the value at 10th element from the base address of the f. So, 0x3104 + 10 = 0x310E.
which is the 10th element in the array str[]. This value is '!'.
So, value = '!', Type = char.

9) *(d+1)

This gives the value stored at d+1 th address. i.e. value at 0xFF00 + 1 = 0xFF01 address. Which is -20.
So, Value = -20, Type = int.

10) **f

This is a double pointer reference. consider this as *(*f). So, first *f = 0xFF03.
Now, *(0xFF03). This address references to the address 0xFF00, and the value at that is 3.
So, *(0xFF03) = 3.
So, value = 3, type = int

11) str[e[4]]

First e[4] indicates the 4+1 th = 5th element in e[], which is 5. So, str[5].
Now, str[5] indicates the 5+1 = 6th element in str[], which is 'n'.
So, Value = 'n', Type = char

12) str[1]

This gives the value at 1+1 = 2nd element in str[], which is 'a'.
So, value = 'a', Type = char

13) d

This gives the value stored at d. Which is 0xFF00.
So, Value = 0xFF00, type = int pointer.

14) d+a

This gives the address stored in d plus the number a. So, 0xFF00 + 3.
So, (d+a) = 0xFF03
So, Value = 0xFF03, type = int pointer

15) &f

This gives the address of the pointer **f. This will be of pointer type.
So, Value = 0x3104, type = int pointer.

16) e

This will give the base address of the array e[]. Which is 0xFF04.
So, Value = 0xFF04, type = int pointer.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote