Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Structures, Unions, Enums Questions
C programming — evaluate this self-referential structure declaration for correctness. struct emp { int ecode; struct emp e; / pointer to the same struct type (self-reference) */ }; Is there any language error in the declaration above?
C programming — identify the compile-time issue in this bit-field struct definition and sizeof usage. #include
int main() { struct a { float category:5; /* bit-field on float / char scheme:4; / small bit-field on char (non-standard extension) */ }; printf("size=%d", (int)sizeof(struct a)); return 0; } What is the correct diagnosis?
C programming — spot the error related to forward declarations and prototypes. #include
#include
void modify(struct emp*); /* prototype uses struct emp before its declaration / struct emp { char name[20]; int age; }; int main() { struct emp e = {"Sanjay", 35}; modify(&e); printf("%s %d", e.name, e.age); return 0; } void modify(struct emp p) { p->age = p->age + 2; } What is the correct assessment for standard C?
C programming on a 16-bit platform — analyze this bit-field width for validity. #include
int main() { struct bits { int i:40; /* 40 bits requested in a 16-bit environment */ } bit; printf("%d", (int)sizeof(bit)); return 0; } What is the correct diagnosis?
C language concept — are nested unions allowed in C? Statement: Nested unions are allowed.
C language concept — can a structure be nested inside another structure? Statement: A structure can be nested inside another structure.
In C programming, can a union contain members of different sizes, and what does that imply for its overall size allocation?
In C, when should you use the -> operator to access members, and what kinds of types does it work with?
C enumerations: choose the correct statement about scope, values, and size control.
In C, does the . operator access members from a structure variable (as opposed to a pointer)?
In C, can a structure contain a nested union as one of its members?
In C, can bit-fields be declared inside a union?
In C, may a structure contain a pointer to the same structure type (self-referential struct)?
In C, can a structure contain members of similar or dissimilar (heterogeneous) types?
In C, is it possible to create an array of pointers to structures?
Given char = 1 byte, int = 2 bytes, and long int = 4 bytes, will the structure below always occupy exactly 7 bytes? Explain considering alignment and padding. struct ex { char ch; int i; long int a; }
In C programming, can we directly declare an array whose elements are bit-fields, or must bit-fields be members of a struct only? Explain the correct approach with a short note on why arrays of plain bit-fields are not allowed.
In C, is the size of a union always exactly equal to the size of its longest (largest) member, or can alignment/padding make the union larger?
In C, can a structure safely include a member that points to an object of the same structure type (a self-referential struct), and when is this useful?
C I/O and serialization: If we write the following struct instance with fwrite(), can we read it back with fread() and get the original data reliably across runs and machines? struct emp { char n; int age; }; struct emp e = "CuriousTab", 15; / pointer to string literal */ FILE *fp; fwrite(&e, sizeof(e), 1, fp);
1
2
3