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.
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_tcontains twodoublevariables,whenandwhat. Since adoublerequires 8 bytes,this_trequires 2 * 8 = 16 bytes.
Next, let's calculate the size of that_t:
that_tcontains an arraywhenof 5this_tobjects. Sincethis_trequires 16 bytes,whenrequires 5 * 16 = 80 bytes.that_talso contains an arraywhatof 4intvariables. Since anintrequires 4 bytes,whatrequires 4 * 4 = 16 bytes.- Finally,
that_tcontains an arrayeverof 4doublevariables. Since adoublerequires 8 bytes,everrequires 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.
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
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.