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

Given this struct on a 32-bit architecture, what is sizeof(struct thestruct)? st

ID: 3867673 • Letter: G

Question

Given this struct on a 32-bit architecture, what is sizeof(struct thestruct)?

struct thestruct {
    int A;
     int B:1;
     char* C;
     double d;
};


-------------------------------------------------

What is the size of each element in (struct thestruct)?

struct thestruct {
    int A;
     int B:1;
     char* C;
     double d;
};
-------------------------------------------


What ordering of items in (struct thestruct) would result in the smallest struct size?

struct thestruct {
    int A;
     int B:1;
     char* C;
     double d;
};
----------------------------------------------------


What would be the sizeof(struct thestruct) if you optimized it for smallest size?

struct thestruct {
    int A;
     int B:1;
     char* C;
     double d;
};

Explanation / Answer

[1] Total Size = 24

[2]
Size = size of A + size of B+ size of C + size of D
       = 4 + 4 +8 +8
       = 24

[3] The order of fields in a struct does matter - the compiler is not allowed to reorder fields, so the size of the struct may change as the result of adding some padding.In this case, however, you are defining a so-called flexible member, an array the size of which you can change.
So no Arrya difine in Struct defination.

Same Size = 24

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