[go: up one dir, main page]

0% found this document useful (0 votes)
58 views22 pages

MCQ On ARRAY

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 22

MCQ on ARRAY

• Which of the following correctly declares an


array?
a) int array[10];
b) int array;
c) array{10};
d) array array[10]
• Which of the following correctly declares an
array?
a) int array[10];
b) int array;
c) array{10};
d) array array[10]
• What is the index number of the last element
of an array with 9 elements?
a) 9
b) 8
c) 0
d) Programmer-defined
• What is the index number of the last element
of an array with 9 elements?
a) 9
b) 8
c) 0
d) Programmer-defined
•  What is a array?
a) An array is a series of elements of the same
type in contiguous memory locations
b) An array is a series of element
c) An array is a series of elements of the same
type placed in non-contiguous memory
locations
d) None of the mentioned
•  What is a array?
a) An array is a series of elements of the same
type in contiguous memory locations
b) An array is a series of element
c) An array is a series of elements of the same
type placed in non-contiguous memory
locations
d) None of the mentioned
• Which of the following accesses the seventh
element stored in array?
a) array[6];
b) array[7];
c) array(7);
d) array;
• Which of the following accesses the seventh
element stored in array?
a) array[6];
b) array[7];
c) array(7);
d) array;
• Which of the following gives the memory
address of the first element in array?
a) array[0];
b) array[1];
c) array(2);
d) array;
• Which of the following gives the memory
address of the first element in array?
a) array[0];
b) array[1];
c) array(2);
d) array;
What will be the output of the this program?

#include <stdio.h>
using namespace std;
int main ()
{
int array[] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0; n < 8; n++) {
result += array[n];
}
cout << result;
return 0;
}
• a) 25
b) 26
c) 27
d) None of the mentioned
• a) 25
b) 26
c) 27
d) None of the above
• Explanation: We are adding all the elements in
the array and printing it. Total elements in the
array is 7, but our for loop will go beyond 7
and add a garbage Value
What is the output of this program?
1.#include <stdio.h>
2.using namespace std;
3.int main()
4.{
5.char str[5] = "ABC";
6.cout << str[3];
7.cout << str;
8.return 0;
9.}
• a) ABC
b) ABCD
c) AB
d) None of the mentioned
• a) ABC
b) ABCD
c) AB
d) None of the mentioned
 What is the output of this program?

1.#include <stdio.h>
2.using namespace std;
3.int main()
4.{
5.int array[] = {10, 20, 30};
6.cout << -2[array];
7.return 0;
8.}
• a) -15
b) -30
c) compile time error
d) garbage value
• Explanation: It’s just printing the negative
value of the concern element.
•  Which of the following is a two-dimensional
array?
• A. array anarray[20][20];
B. int anarray[20][20];
C. int array[20, 20];
D. char array[20];
• What is the index number of the last element
of an array with 29 elements?
A. 29
B. 28
C. 0
D. Programmer-defined
• An array elements are always stored in
________ memory locations.
•  Sequential
•  Random
•  Sequential and Random
•  None of the above

You might also like