3. Evaluate pointer expressions (40 points) The table below lists a set of C var
ID: 3852030 • Letter: 3
Question
3. Evaluate pointer expressions (40 points) 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 Value(s) int a int b char c int* d int e[10] Address 0xFF00 0xFF01 0xFF02 0xFF03 0xFF04 -20 0xFF00 (1,1,2,3, 5,8,13 ,21,34,0 int** f 0x3104 0xFF03 char str [50] 0x3105 "The wave of the future is technology"Explanation / Answer
1) *d = *(value of d) = *(address 0xFF00) = value in address 0xFF00 = 3
Result = 3
2) str = value of str = "The wave of the future is technology"
Result = "The wave of the future is technology"
3) a*b = (value of a) * (value of b) = 3*-20 = -60
Result = -60
4) e[a] = e[value of a] = e[3] = value at index 3 in array e = 3
Result = 3
5) e[5] = value at index 5 in array e = 8
Result = 8
6) (*f)[10] = (*(value of f))[10] = (*(0xFF03))[10] = (value in address 0xFF03)[10] = (address 0xFF00)[10] = value at addres (0xFF00+10*size of int) [here int because, f is pointer to pointer to int.Here size of int is 1 byte]
Result = value at address 0xFF0A
7) *d + 1 = (*d)+1 = (*(value of d))+1 = (*(0xFF00))+1 = value at address 0xFF00 + 1 = 3+1 = 4
Result = 4
8) f[10] = (value of f) + 10*size of int = 0xFF03+10 = 0xFF03+A = 0xFF0D
Result = 0xFF0D
9) *(d+1) = *(value of d + 1*size of int) = *(0xFF00 + 1) = *(0xFF01) = value at address 0xFF01 = -20
Result = -20
10) d[2] = *(value of d + 2*size of int) = *(0xFF00 + 2) = *(0xFF02) = value at address 0xFF02
// This is an error. Because address is pointing to char type. but d is defined to point to int type.
11) str[0] = character at index 0 in array str = 'T'
Result = 'T'
12) str[1] = character at index 1 in array str = 'h'
Result = 'h'
13) *f = *(value of f) = *(0xFF03) = value at address 0xFF03 = 0xFF00
Result = 0xFF00
14) f = value of f = 0xFF03
Result = 0xFF03
15) **f = *(*f) = *(0xFF00) = value at address 0xFF00 = 3
Result = 3
16) &f = base address of f = 0x3104
Result = 0x3104
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.