Which of these best describes an array?
MCQs Question.
Which of the following is the best answer for an array?
(A). A data structure that shows a hierarchical behavior
(B). Container of objects of mixed types
(C). Container of objects of similar types
(D). All of these
Answer: Container of objects of similar types
Example of the Program in C (showing an array as a Container of objects of similar types)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | // Program to take 3 values from the user and store them in an array // Print the elements stored in the array #include <stdio.h> int main() { int Array_with_objects_of_similar_types[3]; printf("Enter 3 integers: "); // taking input and storing it in an array for(int loop = 0; loop < 3; ++loop) { scanf("%d", &Array_with_objects_of_similar_types[loop]); } printf("Displaying integers: "); // printing elements of an array for(int loop = 0; loop < 3; ++loop) { printf("%d\n", Array_with_objects_of_similar_types[loop]); } return 0; } |
Output
Enter 3 integers: 4
5
6
Displaying integers: 4
5
6
Example of the Program in C++ (showing an array as a Container of objects of similar types)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | // Program to take 3 values from the user and store them in an array // Print the elements stored in the array #include <iostream> using namespace std; int main() { int Array_with_objects_of_similar_types[3]; cout<<"Enter 3 integers: "<<endl; // taking input and storing it in an array for(int loop = 0; loop < 3; ++loop) { cin>>Array_with_objects_of_similar_types[loop]; } cout<<"Displaying integers: "<<endl; // printing elements of an array for(int loop = 0; loop < 3; ++loop) { cout<<Array_with_objects_of_similar_types[loop]<<endl; } return 0; } |
Output
Enter 3 integers:
8
9
10
Displaying integers:
8
9
10
Highly Recommended C++ Important MCQs with Explanation
- Which symbol is used to create multiple inheritances?
- If a derived class object is created, which constructor is called first?
- Which of the following is not a type of constructor?
- a ____ is a member function that is automatically called when a class object is __.
- What is the output of the following code in C++?
- How many times will the following code print?
- Which of the following is a procedural language?
- Which of the following is not a programming language?
- Which of the following is not an example of high-level language?
- While declaring pointer variables which operator do we use?
- To which does the function pointer point to?
- Which of these best describes an array?