Structures, Unions, Enums Questions

Practice Structures, Unions, Enums MCQs with answers and explanations. Page 3 of 3.

Category
C Programming
Topic
Structures, Unions, Enums
Page
3 / 3
Mode
Practice

Questions

Open any question to view the answer and explanation.

In standard C, is there a built-in, portable way to print the symbolic names of enum constants at runtime, or must we create our own mapping?
Open
View answer
Accessing union members in C: Do we always need the address-of (&) operator, or do we use the member access operator (.) to read/write fields?
Open
View answer
Union layout in C: Must all members of a union have the same size, or can members differ in size with the union sized to fit the largest?
Open
View answer
Storage class defaults in C: If you declare a structure variable inside a block without an explicit storage-class specifier, what is its default storage duration?
Open
View answer
C typedef with struct tag reuse: Will the following declaration compile and work as intended, creating both a struct tag and a typedef of the same name? typedef struct s { int a; float b; } s;
Open
View answer
Flexible storage for names: Will the following C code allocate enough space for a variable-length name and print it correctly? #include<stdio.h> #include<malloc.h> struct emp { int len; char name[1]; }; int main() { char newname[] = "Rahul"; struct emp *p = (struct emp *) malloc(sizeof(struct emp) - 1 + strlen(newname) + 1); p->len = strlen(newname); strcpy(p->name, newname); printf("%d %s ", p->len, p->name); return 0; }
Open
View answer
In C programming, can we create a union whose members are pointers (for example, to allow the same storage to hold either an int* or a char*)? Choose the most accurate statement.
Open
View answer

Practice smarter

Solve a few questions daily and revisit weak topics regularly to improve accuracy.