Study C MCQ Questions and Answers on Structures and Pointers. C Structures are widely used in the code of hardware drivers and operating systems. Easily attend technical job interviews after reading these Multiple Choice Questions.
Go through C Theory Notes on Structures and Pointers before studying these questions.
int main() { struct car {int color;}; struct garage { struct car mycar[10]; }gar; struct car c1={5}; gar.mycar[0]=c1; printf("%d",gar.mycar[0]); return 0; }
It is an example of nested structures.
int main() { struct books{ int pages; char str[4]; }b; printf("%d",sizeof(b)); return 0; }
2+4= 6 bytes.
int main() { struct books{ int pages; char str[4]; }*ptr; printf("%d",sizeof(ptr)); return 0; }
Memory reserved will be the size of sum of individual elements.
Yes. If you pass a structure variable by value without & operator, only a copy of the variable is passed. So changes made within that function do not reflect in the original variable.
void show(int,int); int main() { struct paint{ int type; int color; }p; p.type=1; p.color=5; show(p.type,p.color); return 0; } void show(int a,int b) { printf("%d %d",a,b); }
int main() { struct paint{ int type; int color; }p1, p2; p1.type=1; p1.color=5; if(sizeof(p1)==sizeof(p2)) { printf("SAME"); } else { printf("DIFFERENT"); } return 0; }
Yes. Before and after initialization, size of a structure variable does not change.