Exercises: Topic: Array
Exercises: Topic: Array
TOPIC : ARRAY
1. Which of the following correctly declares an array?
a) int name[10];
b) int name;
c) name{10};
d) array name[10];
2. Identify the correct syntax to access the 25 element for the array named anarray with 25
elements.
e) anarray=+25
f) anarray[24]
g) anarray[25]
h) anarray[last]
3. Which is the correct statement for declaring and initializing an array?
int score[ ]={90, 88, 70, 89};
i. The size element of the array is 4.
ii. score[1]=90;
iii. The type of each element is integer
iv. The name of the array is score.
a) i and ii only
b) iii and iv only
c) i, iii and iv only
d) ii, iii and iv only
4. Analyze and find the value of num[0][1] and num[2][1] for two dimensional array below.
int num[3][2]={1,2,3,4,5,6};
a) 3,5
b) 2,3
c) 3,6
d) 2,6
5. The array cost holds the following data:
What is the value in the variable cost after the following statement is executed?
total = cost[4];
a) 4.99
b) 25.25
c) 33.65
d) 45.99
6. Which of the following shows the correct syntax to declare and initialize a four element char
array named block.
a) char block[4]={“a”,”b”,”c”};
b) char block[3]={‘a’,’b’,’c’,’d’};
c) char block[4]={‘a’ ’b’ ’c’ ’d’};
d) char block[4]={‘a’,’b’,’c’,’d’};
12. Write an array declaration of StudentPointer as an double array with 3 rows and 4 columns.
13. Based on the syntax below, change the value of last element to 10.
int state[2][3]={1,2,3,4,5,6};
14. Write the syntax to declare an array.
16. Based on fragment code below, write the value for each statement.
int num[3][4]={{2,4,6,8},{3,6,9,12},{1,5,10,13}};
i. cout<<num[2][3];
ii. cout<<num[0][2];
17. Complete the table below.
int X [25];
float Y[15];
char Z[30];
19. Write a complete program to takes 6 price of products from the user, store it in an array and
calculate the average of the price.
Declare a double two dimensional array that will holds marks for 5
students for 3 quizzes. Ask the user to keyin marks for all 5 students for
their quiz 1, quiz 2 and quiz 3. Calculate the average marks for all 3
quizzes took by each of the student. Store the calculated average mark
in the array that you had declared above. Display ALL the marks and
average marks in a table form as below.