What will be the output of the following C++ code?
#include <stdio.h>
#include<iostream>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main()
{
for (temp = 0; temp < 5; temp++)
{
result += array1[temp];
}
for (temp = 0; temp < 4; temp++)
{
result += array2[temp];
}
cout << result;
return 0;
}
#include <stdio.h>
#include<iostream>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main()
{
for (temp = 0; temp < 5; temp++)
{
result += array1[temp];
}
for (temp = 0; temp < 4; temp++)
{
result += array2[temp];
}
cout << result;
return 0;
}A. 6553
B. 6533
C. 6522
D. 12200
Answer: Option B
Related Questions on Arrays and Strings in C plus plus
What is the correct way to declare a one-dimensional array in C++?
A. int* arr = new int[size];
B. int[] arr = new int[size];
C. int arr = new int[size];
D. int arr[size];
How do you access the third element of an array named 'arr' in C++?
A. arr(3)
B. arr[3]
C. arr[2]
D. arr(2)
What is the size of the following array declaration in C++: char str[10];?
A. 11
B. 10
C. Depends on the length of the string assigned to 'str'
D. None of these
What is the purpose of the 'strlen()' function in C++?
A. Concatenates two strings
B. Compares two strings
C. Returns the length of a null-terminated string
D. Copies a string to another string

Join The Discussion