MCQ On ARRAY
MCQ On ARRAY
MCQ On ARRAY
#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