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

1. Write a short note on struct and union data types. Give examples and mention

ID: 3568673 • Letter: 1

Question

1. Write a short note on struct and union data types. Give examples and mention their usage.

2. Consider the following C code fragment segment. Answer the following questions

struct RecA{

char x;

int y;

};

typedef struct RecA RecA;

struct RecA a;

RecA b;

struct RecA c;

struct{

int y;

char x; } d;

struct{

char p;

int q; } e;

a) Structurally equivalent variables:

b) Name equivalent variables:

3. Draw the symbol table structure at line 12 and 15 for the following code representation.

struct{

int a;

char b;

double c; } x = {1, 'a', 2.5}

void p(){

struct{

double a;

int b;

char c; } y = {1.2, 2, 'b'}

printf("%d, %c, %g ", x.a, x.b, x.c)

printf("%f, %d, %c ", y.a, y.b, y.c)

}

main(){

p();

return 0;

}

Explanation / Answer

STRUCTURES:
structures are used to group together different types of variables under the same name. For example you could create a structure