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

The first byte of memory below is xFF2A. int main() { float a= 32.5, b; int c =

ID: 3550195 • Letter: T

Question

The first byte of memory below is xFF2A.

int main()

{

            float a= 32.5, b;

            int c = 5, d = 4.5, x;

            float  *q, *r;

            int *s, *t;

            q = &a;

            r = &b;

            s = &x;

            t = &d;

            *r = c%d;

            *s = *t + c;

t

s

r

q

x

d

c

b

a

value

address

xFF2A

  

     

t

     

s

     

r

     

q

     

x

     

d

     

c

     

b

     

a

     

value

     

     

     

     

     

     

     

     

     

     

address

     

xFF2A

     

     

     

     

     

     

     

     

  

Explanation / Answer

Lets start with the addresses It starts from the bottom up.

The first we know is t = xFF2A

They tell us that pointers are 4 bytes so we start going up the list


s = xFF2A + 4 = xFF2E

r = xFF2E + 4 = xFF32

q = xFF32 + 4 = xFF36


Now we have the pointers done, ints and floats are also 4 bytes each so it makes it pretty easy. Just advance up the list 1 at a time.


x = xFF36 + 4 = xFF3A

d = xFF3A + 4 = xFF3E

c = xFF3E + 4 = xFF42

b = xFF42 + 4 = xFF46

a = xFF46 + 4 = xFF4A


That is all the addresses, now to figure out the values


t is a pointer that holds the address to d

t = xFF3E


s is a pointer that holds the address to x

s = xFF3A


r is a pointer that holds the address to b

r = xFF46


q is a pointer that holds the address to a

q = xFF4A


x is a int, the value is determined by the last line "*s = *t + c;"

since s is the pointer that holds x, *s represents the value in x. and *t means the value in d so the final equation is

x = 4.5 + 5, but since x is an int the decimal is truncated leaving x = 9


d's value is pretty simple at 4.5 but since it is an int what really shows is d = 4


c's value is just 5, c = 5


b's value is contained in the 2nd to last line "*r = c%d;" The same idea is used in finding the value for x

the value of b = c mod d, or b = 5 mod 4.5 = 1


a's value is just 32.5, a = 32.5

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