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
On a 16-bit DOS/Turbo C platform where pointers are 2 bytes in small/near memory models, consider the following node structure allocation. What are the sizes printed for the pointer variables p and q? #include
#include
int main() { struct node { int data; struct node *link; }; struct node *p, *q; p = (struct node *) malloc(sizeof(struct node)); q = (struct node *) malloc(sizeof(struct node)); printf("%d, %d ", sizeof(p), sizeof(q)); return 0; }
In C, a union shares storage among its members. For the union below, values are assigned sequentially to a and b. What will be printed when v.a is output? #include
int main() { union var { int a, b; }; union var v; v.a = 10; v.b = 20; printf("%d ", v.a); return 0; }
On a 16-bit Turbo C/DOS platform, consider a struct with three bit-fields declared with base type int. What is sizeof the struct value instance? #include
int main() { struct value { int bit1:1; int bit3:4; int bit4:4; } bit; printf("%d ", sizeof(bit)); return 0; }
In C, enum constants are not modifiable lvalues. For the enumeration below with explicit values, what will happen if we attempt to pre-increment MON inside printf? #include
int main() { enum days { MON = -1, TUE, WED = 6, THU, FRI, SAT }; printf("%d, %d, %d, %d, %d, %d ", ++MON, TUE, WED, THU, FRI, SAT); return 0; }
Work with an array of structs and pointer arithmetic on arrays. What output is produced by accessing c[1].courseno and (*(c + 2)).coursename in the code below? #include
int main() { struct course { int courseno; char coursename[25]; }; struct course c[] = { {102, "Java"}, {103, "PHP"}, {104, "DotNet"} }; printf("%d ", c[1].courseno); printf("%s ", (*(c+2)).coursename); return 0; }
Evaluate bitwise precedence and grouping. For i = 4 and j = 8, what is printed by the following expression sequence using & (AND), ^ (XOR), and | (OR)? #include
int main() { int i = 4, j = 8; printf("%d, %d, %d ", i | j & j | i, i | j & j | i, i ^ j); return 0; }
In C programming, determine the output of this program using a union of int and char[2]. #include
int main() { union A { int i; char ch[2]; }; union A u; u.ch[0] = 3; u.ch[1] = 2; printf("%d, %d, %d ", u.ch[0], u.ch[1], u.i); return 0; }
On a 16-bit platform, what is sizeof for this enumeration variable? #include
int main() { enum value { VAL1 = 0, VAL2, VAL3, VAL4, VAL5 } var; printf("%d ", (int)sizeof(var)); return 0; }
In C bit-fields, predict the printed values when using 1-bit and 4-bit signed fields. #include
int main() { struct value { int bit1 : 1; int bit3 : 4; int bit4 : 4; } bit = { 1, 2, 13 }; printf("%d, %d, %d ", bit.bit1, bit.bit3, bit.bit4); return 0; }
In C, evaluate the values printed for enumerators with explicit and implicit assignments. #include
int main() { enum days { MON = -1, TUE, WED = 6, THU, FRI, SAT }; printf("%d, %d, %d, %d, %d, %d ", MON, TUE, WED, THU, FRI, SAT); return 0; }
In C bit-fields, what is printed for a 1-bit signed field initialized to 1? #include
int main() { struct byte { int one : 1; }; struct byte var = { 1 }; printf("%d ", var.one); return 0; }
Turbo C (DOS): effect of structure assignment with a char* and using strupr on the copy. #include
#include
int main() { struct emp { char n; int age; }; struct emp e1 = { "Dravid", 23 }; struct emp e2 = e1; strupr(e2.n); printf("%s ", e1.n); return 0; }
Enumerations in C: determine the printed integral values for three students’ statuses. #include
int main() { enum status { pass, fail, absent }; enum status stud1, stud2, stud3; stud1 = pass; stud2 = absent; stud3 = fail; printf("%d %d %d ", stud1, stud2, stud3); return 0; }
C typedef and self-referential pointers: identify whether this declaration is valid. typedef struct data mystruct; struct data { int x; mystruct b; };
C structures: is this self-referential member declaration valid or an error? struct emp { int ecode; struct emp e; };
C unions and initializers: identify the error in the following union initializations. #include
int main() { union a { int i; char ch[2]; }; union a z1 = { 512 }; union a z2 = { 0, 2 }; return 0; }
C programming — identify the compile-time issue in this bit-field example. #include
int main() { struct bits { /* Attempting a bit-field on a floating type */ float f:2; } bit; printf("%d", (int)sizeof(bit)); return 0; } Which option best describes the problem (if any)?
C programming — identify the issue (if any) in this structure input loop. #include
int main() { struct emp { char name[20]; float sal; }; struct emp e[10]; int i; for(i = 0; i <= 9; i++) scanf("%s %f", e[i].name, &e[i].sal); return 0; } Does this code have a language/compilation error?
C programming — determine whether these two structs can be compared with ==. #include
int main() { struct emp { char n[20]; int age; }; struct emp e1 = {"Dravid", 23}; struct emp e2 = e1; if (e1 == e2) printf("The structures are equal"); return 0; } What is the correct assessment?
C programming — find the error in assigning to a char array member of a struct. #include
int main() { struct emp { char name[25]; int age; float bs; }; struct emp e; e.name = "Suresh"; /* assignment to array member */ e.age = 25; printf("%s %d", e.name, e.age); return 0; } What is the correct diagnosis?
1
2
3