ExamTray App is now Available on Google Play EXAMTRAY android app link

 

C MCQ Questions and Answers on Structures and Pointers 1

Image
C MCQ Questions from ExamTray.com

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.



1) What is a structure in C language.?
A) A structure is a collection of elements that can be of same data type.
B) A structure is a collection of elements that can be of different data type.
C) Elements of a structure are called members.
D) All the above
Answer [=]
D
Explanation:
struct insurance
{
int age;
char name[20];
}
2) Choose a correct statement about C structure elements.?
A) Structure elements are stored on random free memory locations
B) structure elements are stored in register memory locations
C) structure elements are stored in contiguous memory locations
D) None of the above.
Answer [=]
C
3) A C Structure or User defined data type is also called.?
A) Derived data type
B) Secondary data type
C) Aggregate data type
D) All the above
Answer [=]
D
4) What are the uses of C Structures.?
A) structure is used to implement Linked Lists, Stack and Queue data structures
B) Structures are used in Operating System functionality like Display and Input taking.
C) Structure are used to exchange information with peripherals of PC
D) All the above
Answer [=]
D
5) What is the output of C program with structures.? int main() { struct tree { int h; int w; }; struct tree tree1={10}; printf("%d ",tree1.w); printf("%d",tree1.h); return 0; }
A) 0 0
B) 10 0
C) 0 10
D) 10 10
Answer [=]
C
Explanation:
struct tree tree1={10};

Assigns the value to corresponding member. Remaining are set to Zero. So w is zero.


 
6) What is the output of C program with structures.? int main() { struct tree { int h; int rate; }; struct tree tree1={0}; printf("%d ",tree1.rate); printf("%d",tree1.h); return 0; }
A) 0 0
B) -1 -1
C) NULL NULL
D) Compiler error
Answer [=]
A
Explanation:

Easiest way of initializing all structure elements.

struct tree tree1={0};
7) What is the output of C program.? int main() { struct laptop { int cost; char brand[10]; }; struct laptop L1={5000,"ACER"}; struct laptop L2={6000,"IBM"}; printf("Name=%s",L1.brand); return 0; }
A) ACER
B) IBM
C) Compiler error
D) None of the above
Answer [=]
A
Explanation:

You can initialize structure members at the time of creation of Structure variables.

8) What is the output of C program with structures pointers.? int main() { struct forest { int trees; int animals; }F1,*F2; F1.trees=1000; F1.animals=20; F2=&F1; printf("%d ",F2.animals); return 0; }
A) 0
B) 20
C) Compiler error
D) None of the above
Answer [=]
C
Explanation:

F2.animal is not allowed as F2 is a pointer to structure variable. So use ARROW operators. F2->animal.

9) What int main() { struct bus { int seats; }F1, *F2; F1.seats=20; F2=&F1; F2->seats=15; printf("%d ",F1.seats); return 0; }
A) 15
B) 20
C) 0
D) Compiler error
Answer [=]
A
Explanation:

DOT operator is used with a structure variable. ARROW operator is used with a pointer to structure variable.

10) What is the output of C program with structure arrays.? int main() { struct pens { int color; }p1[2]; struct pens p2[3]; p1[0].color=5; p1[1].color=9; printf("%d ",p1[0].color); printf("%d",p1[1].color); return 0; }
A) 5 5
B) 5 9
C) 9 5
D) Compiler error
Answer [=]
B
Explanation:

You can declare and use structure variable arrays.

11) What is the output of C program with structure array pointers.? int main() { struct car { int km; }*p1[2]; struct car c1={1234}; p1[0]=&c1; printf("%d ",p1[0]->km); return 0; }
A) 0
B) 1
C) 1234
D) Compiler error
Answer [=]
C
Explanation:

It is allowed to create array of pointers to structure variables.

12) What is the size of a C structure.?
A) C structure is always 128 bytes.
B) Size of C structure is the total bytes of all elements of structure.
C) Size of C structure is the size of largest element.
D) None of the above
Answer [=]
B
Explanation:

Individually calculate the sizes of each member of a structure and make a total to get Full size of a structure.

13) Choose a correct statement about C structures.
A) A structure can contain same structure type member.
B) A structure size is limited by only physical memory of that PC.
C) You can define an unlimited number of members inside a structure.
D) All the above.
Answer [=]
D
14) What is the output of C program with structures.? int main() { structure hotel { int items; char name[10]; }a; strcpy(a.name, "TAJ"); a.items=10; printf("%s", a.name); return 0; }
A) TAJ
B) Empty string
C) Compiler error
D) None of the above
Answer [=]
C
Explanation:

Keyword used to declare a structure is STRUCT not structURE in lowercase i.e struct.

15) What is the output of C program.? int main() { struct book { int pages; char name[10]; }a; a.pages=10; strcpy(a.name,"Cbasics"); printf("%s=%d", a.name,a.pages); return 0; }
A) empty string=10
B) C=basics
C) Cbasics=10
D) Compiler error
Answer [=]
C
Explanation:

pages and name are structure members. a is a structure variable. To refer structure members use a DOT operator say a.name.

16) Choose a correct statement about C structures.
A) Structure elements can be initialized at the time of declaration.
B) Structure members can not be initialized at the time of declaration
C) Only integer members of structure can be initialized at the time of declaraion
D) None of the above
Answer [=]
B
Explanation:
struct book
{ 
int SNO=10; //not allowed
};
17) Choose a correct statement about C structure.? int main() { struct ship { }; return 0; }
A) It is wrong to define an empty structure
B) Member variables can be added to a structure even after its first definition.
C) There is no use of defining an empty structure
D) None of the above
Answer [=]
C
18) What is the output of C program.? int main() { struct ship { int size; char color[10]; }boat1, boat2; boat1.size=10; boat2 = boat1; printf("boat2=%d",boat2.size); return 0; }
A) boat2=0
B) boat2=-1
C) boat2=10
D) Compiler error
Answer [=]
C
Explanation:

Yes, it is allowed to assign one structure variables. boat2=boat1. Remember, boat1 and boat2 have different memory locations.

19) What is the output of C program with structures.? int main() { struct ship { char color[10]; }boat1, boat2; strcpy(boat1.color,"RED"); printf("%s ",boat1.color); boat2 = boat1; strcpy(boat2.color,"YELLOW"); printf("%s",boat1.color); return 0; }
A) RED RED
B) RED YELLOW
C) YELLOW YELLOW
D) Compiler error
Answer [=]
A
Explanation:

boat2=boat1 copies only values to boat2 memory locations. So changing boat2 color does not change boat1 color.

20) What is the output of C program with structures.? int main() { struct tree { int h; } struct tree tree1; tree1.h=10; printf("Height=%d",tree1.h); return 0; }
A) Height=0
B) Height=10
C) Height=
D) Compiler error
Answer [=]
B
Explanation:

Notice a missing semicolon at the end of structure definition.

struct tree
{
   int h;
};