Arrays(C++ Programming ) Questions and Answers
Explanation:-
Answer: Option D. -> compile time errorThe conversion is invalid in this array. So it will arise error. The following compilation error
will be raised:
cannot convert from 'int *' to 'int'
Explanation:-
Answer: Option D. -> None of the mentionedWe 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.
Question 5.
1.
#include
2.
using namespace std;
3.
int array1[] = {1200, 200, 2300, 1230, 1543};
4.
int array2[] = {12, 14, 16, 18, 20};
5.
int temp, result = 0;
6.
int main()
7.
{
8.
for (temp = 0; temp < 5; temp++) {
9.
result += array1[temp];
10.
}
11.
for (temp = 0; temp < 4; temp++) {
12.
result += array2[temp];
13.
}
14.
cout
What will be the output of this program?
1.
#include
2.
using namespace std;
3.
int array1[] = {1200, 200, 2300, 1230, 1543};
4.
int array2[] = {12, 14, 16, 18, 20};
5.
int temp, result = 0;
6.
int main()
7.
{
8.
for (temp = 0; temp < 5; temp++) {
9.
result += array1[temp];
10.
}
11.
for (temp = 0; temp < 4; temp++) {
12.
result += array2[temp];
13.
}
14.
cout
Explanation:-
Answer: Option B. -> 6533In this program we are adding the every element of two arrays. Finally we got output as 6533.
Output:
$ g++ array.cpp
$ a.out
6533