Arrays
1.
Which of the following correctly declares an array ?
2.
What is the index number of the last element of an array with 29 elements ?
3.
Which of the following is a two-dimensional array ?
4.
Which of the following correctly accesses the seventh element stored in foo, An array with 100 elements ?
5.
Which of the following gives the memory address of the first element in array foo, an array with 100
elements ?
6.
What is a array ?
7.
Which of the following accesses the seventh element stored in array ?
8.
Which of the following gives the memory address of the first element in array ?
9.
What will be the output of this program ?
#include <stdio.h>
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;
}
10.
#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;
}