Question

Assuming shorts are 2 bytes long, and pointers are 8 bytes long, how many bytes does...

Assuming shorts are 2 bytes long, and pointers are 8 bytes long, how many bytes does this program need? short a = 3; short b = a; short * c = &a; *c = b++; short & d = a; short & e = b; short * f = c; e = *f + d; (a) 0 (b) 4 (c) 8 (d) 12 (e) 16 (f) 20 (g) 24 (h) 28

Please confirm. My answer: (f) 20

short a = 3; //2 bytes

short b = a; // +2

short * c = &a; //pointer variable +8

*c = b++; short & d = a;

//reference variable +0 bytes

short & e = b;//reference variable +0

bytes short * f = c;//pointer variable +8

e = *f + d;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: (f) 20 bytes

short a = 3; //2 bytes

short b = a; //2 bytes

short * c = &a; // pointer variable = 8 bytes

*c = b++; //computation = 0 bytes

short & d = a; //reference variable just aliases the name, it doesn't takes space. so 0 bytes

short & e = b; //Reference variable. so 0 bytes.

short * f = c; //pointer variable = 8 bytes

e = *f + d; //it is same as b = *f + a, so the memory for them is already allocated and it is just computation. So 0 bytes.

Total memory needed = 2 + 2 + 8 + 0 + 0 + 0 + 8 + 0 = 20 bytes.

Therefore, The given program needs 20 bytes of memory.

Add a comment
Know the answer?
Add Answer to:
Assuming shorts are 2 bytes long, and pointers are 8 bytes long, how many bytes does...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Give the minimum size of each of the following C++ types, assuming that char values occupy one...

    2. Give the minimum size of each of the following C++ types, assuming that char values occupy one byte, short values occupy two bytes, int and float values occupy four bytes, double and long values occupy eight bytes, and pointers occupy four bytes. a) union u type ( double a[3]; int *b; char c[10] b) struct s1type float *d [2]; long e[4] char f[6] short *gi c) struct s2 type ( s1_type s; u type u [2]; int *h[3]; short...

  • Consider a disk with block size = 4096 bytes. A block pointer is 6 bytes and...

    Consider a disk with block size = 4096 bytes. A block pointer is 6 bytes and a record pointer is 8 bytes long. A file has 100,000 records of fixed length. Each record has the following fields and byte size: Name (30), Ssn (9), Dept (9), Address (40), Phone (10), Bdate (8), Sex (1), Job (4) and Salary (4). An additional byte is used as a deletion marked. a. Calculate the record size R in bytes b. Calculate the blocking...

  • State true or false: (6 x 2 = 12 pts) Using -- with a reverse iterator...

    State true or false: (6 x 2 = 12 pts) Using -- with a reverse iterator moves it from the back toward the front of a list b) The body of a do-while loop is always executed at least once. c) If p points to the array element a[j], then p + i points to a[i+j]. d) Any number of pointer variables may point to the same object. In terms of both execution speed and memory usage usually iterative solutions...

  • Pointer (76%) Pointer is a (historical) concept used in C (and C++), but not in any...

    Pointer (76%) Pointer is a (historical) concept used in C (and C++), but not in any other computer languages. Due to C language’s being prevalent however, you need to learn about this. Pointer concept is explained in detail in the power point file of chapter 7 (slides 12, 20 etc. for example). 1. (12%) Printing a variable and its pointer. Consider the C instruction: int p = 0, *pptr = &p; Write a C program that prints the int variable...

  • 17. Given the following definition of function £, what does the expression "t (1: 2: 3]::" return? let rec f listl match listl with 1 I head::rest -> head f resti b. 6 c. 120 d. 123 456...

    17. Given the following definition of function £, what does the expression "t (1: 2: 3]::" return? let rec f listl match listl with 1 I head::rest -> head f resti b. 6 c. 120 d. 123 456 e. g. 14; 5; 6] h. (6; 5; 4] i. Error message j. None of the above 18. Which of the following is the correct meaning of the C declaration "double (*a [n]) "? a is an array of n pointers to...

  • design hash table Suppose you need to design a hash table. The keys themselves are (pointers...

    design hash table Suppose you need to design a hash table. The keys themselves are (pointers to) C-style zero-terminating strings, so the string "foobar" occupies seven bytes. You are interested in minimizing the space used while keeping search time within reasonable bounds. You expect to store 1000 names with (on average) 7 letters each. If, for example, you choose separate chaining with 2000 buckets, the space required will be 24000 bytes: 8000 = (2000 buckets times 4 bytes per bucket...

  • Q1. Suppose we have a virtual memory of size 2 Terabytes (2048GB, or 241 bytes), where...

    Q1. Suppose we have a virtual memory of size 2 Terabytes (2048GB, or 241 bytes), where pages are 8KB (213 bytes) each, and the machine has 4GB (232 bytes) of physical memory.                      a) Compute the number of page table entries needed if all the pages are being used.                       b) Compute the size of the page table if each page table entry also required 4 additional bits (valid, protection, dirty, use). Q2. For this problem, you are given a...

  • Assuming that the switch in Fig. below has been in position A for a long time...

    Assuming that the switch in Fig. below has been in position A for a long time and is moved to position B att = 0, find vo(t)for t > 0. 20 k2 WWE A. 16 + 0.8e-3t/80 V. B. 14.4 + 1.6e-t/24 v. C. 14.4 - 1.6e-t/24 v. D. 16+ 1.6e-3t/80 v. E. None of the above. AB 2 mF 50 40 k22 330k2

  • For C programming How many bytes are allocated in memory to the following line of code:...

    For C programming How many bytes are allocated in memory to the following line of code: double x = -1.75 A) 4 B) 8 C) 16 D) 32 E) 64

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT