Knowee
Questions
Features
Study Tools

Consider the following declarations: typedef struct { double when, what; } this_t; typedef struct { this_t when[5]; int what[4]; double ever[4]; } that_t;If an int variable requires four bytes and a double requires eight bytes, a single object of type that_t requires:64 bytes80 bytes90 bytes128 bytes160 bytes.

Question

Consider the following declarations: typedef struct { double when, what; } this_t; typedef struct { this_t when[5]; int what[4]; double ever[4]; } that_t;If an int variable requires four bytes and a double requires eight bytes, a single object of type that_t requires:64 bytes80 bytes90 bytes128 bytes160 bytes.

🧐 Not the exact question you are looking for?Go ask a question

Solution

To calculate the size of an object of type that_t, we need to add up the sizes of all its member variables.

First, let's calculate the size of this_t:

  • this_t contains two double variables, when and what. Since a double requires 8 bytes, this_t requires 2 * 8 = 16 bytes.

Next, let's calculate the size of that_t:

  • that_t contains an array when of 5 this_t objects. Since this_t requires 16 bytes, when requires 5 * 16 = 80 bytes.
  • that_t also contains an array what of 4 int variables. Since an int requires 4 bytes, what requires 4 * 4 = 16 bytes.
  • Finally, that_t contains an array ever of 4 double variables. Since a double requires 8 bytes, ever requires 4 * 8 = 32 bytes.

Adding these up, a single object of type that_t requires 80 + 16 + 32 = 128 bytes. So, the correct answer is 128 bytes.

This problem has been solved

Similar Questions

Consider the following C declaration. struct {     short s[5];    union {          float y;          long z;     }u; } t;Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, isa.22 bytesb.14 bytesc.18 bytesd.10 bytes

Consider the following C declaration, now assume that objects of the type short, float and long occupy 4 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is

Multi Choice Type QuestionIn a 64-bit system, what is the size of a generic (void) pointer in C?Marks : 1Negative Marks : 0Answer hereIt depends on the data type it points to2 bytes4 bytes8 bytes

Consider the following declarations, designed to record the hours worked by the employees of a company through a given 14-day-long pay period (one fortnight), where each employee works on some subset of the days: #define FORTDAYS 14 #define MAX_EMPLOYEES 1000 typedef struct { int dd, mm, yyyy; double hours_worked; } workday_t; typedef struct { int emp_num; int ndaysworked; workday_t times[FORTDAYS]; double hourly_rate; } timecard_t; timecard_t this_fortnight[MAX_EMPLOYEES]; int num_employees;Which of the following statements is not consistent with the most likely intention of these definitions:Group of answer choicesIf a new employee starts working, then variable num_employees should increase by one, and the new person's emp_num can be any integer value that has not been assigned to another employeeVariable this_fortnight[k].ndaysworked is an integer that counts the number of days worked in the current fortnight by the employee whose employee number is given by this_fortnight[k].emp_num, provided k<num_employeesVariable num_employees should always be in the range from zero to MAX_EMPLOYEESEach instance of variable ndaysworked should always be in the range from zero to FORTDAYSIf a new employee starts working, their emp_num should be taken from the value of num_employees, and then num_employees should be increased by one, so that the employee numbers remain sorted in the array

elect the correct answerWhat is the purpose of the typedef keyword in C?OptionsTo declare a pointerTo define a constantTo declare a new data typeTo create an array

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.