A sensor logger uses the following declarations inside a C17 function. Consider each candidate statement independently, immediately after these declarations.
struct Reading { int code; int samples[2]; }; struct Backup { int code; int samples[2]; }; struct Reading a = { 21, { 6, 8 } }; struct Reading b = { 34, { 2, 5 } }; struct Backup c = { 0, { 0, 0 } };
The candidates are numbered only to identify their table rows.
/* Statement 1 */ b = a; /* Statement 2 */ b.samples = a.samples; /* Statement 3 */ b.samples[1] = a.samples[0]; /* Statement 4 */ b == a; /* Statement 5 */ c = a;
Enter valid if a statement satisfies the C17 language constraints, or invalid otherwise. Assume no casts or compiler extensions.
Unlock full course notes by signing up
Size of a structure with interleaved members
On a 64-bit Linux platform where char, int and double occupy 1, 4 and 8 bytes and each is aligned to its own size, what does sizeof(struct mixed) evaluate to for the declaration below? Give the answer in bytes as a whole number.
Offsets in a log entry structure
A logging tool declares the structure below on a 64-bit Linux platform where char, short, int and double occupy 1, 2, 4 and 8 bytes and each is aligned to its own size. Fill in the byte offset of each remaining member and the total size of the structure, as whole numbers of bytes.
A tagged union inside a structure
A parser stores values as a tagged union, declared below, on a 64-bit Linux platform where char, short, int and double occupy 1, 2, 4 and 8 bytes and each is aligned to its own size. Give each value in bytes as a whole number: the size of union value, the offset of member v within struct tagged, and the size of struct tagged.
Following a copied structure with a shared target
An inventory program copies a structure containing integer counts, an embedded array and a pointer member. Trace the following C17 code, executed inside a function.
Report the final values of stock, a.count and b.local[0]. Every requested value is a count of items; enter exact integers.