wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

ARRAY IN C++

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

How do you declare variables for 5 price of item?

a)

float price1, price2, price3, price4, price5;

b)

float price1to5;

c)

float price(5);

d)

float price[5];

2.

■An array is a group of memory locations that have ______________________________.

a)

the same name and different type

b)

the same name

c)

the same name and the same type.

d)

the different name and type

3.

Two types of Array are:

a)

1 Dimensional Array and 2 Dimensional Array

b)

2 Dimensional Array and 3 Dimensional Array

c)

Linear Array and Dynamic Array

d)

Sequence Array and Non-Sequence Array

4.

Declaration statement for an array named arr with size 4 is

a)

int arr[0];

b)

int arr[5];

c)

int arr(4);

d)

int arr[4];

5.

Declaration and initialize statement for an array named number with 1.1, 2.2 and 3.3 is written as

a)

float number[2] = {1.1, 2.2, 3.3};

b)

int number[3] = {1.1, 2.2, 3.3};

c)

float number[3] = {1.1, 2.2, 3.3};

6.

int a[5]={1,2,3,4,5};


The statement to display the third element of an array a is

a)

cout<< a[2];

b)

cout<< a[3];

7.

Statement to display the fourth element of the array arr.


int arr[5]={12,23,31,42,51};

a)

cout<< arr[4];

b)

cout<< arr[3];

8.

coding to display all character in the array for declaration mark:


char mark[5];

a)

cout<<mark;

b)

cout<<array mark;

c)

cout<<array;

9.

Unlike regular variables, __________ can hold multiple values.

a)

constants

b)

named constants

c)

arrays

d)

floats

10.
In an array, every element has the same
a)
data type
b)
subscript
c)
memory location
d)
all of the above
11.

Given the following declaration, where is the value 77 stored in the scores array?

int scores[] = {83, 62, 77, 97, 86}

a)

scores[0]

b)

scores[1]

c)

scores[2]

d)

scores[3]

12.

What will the following code display?

int numbers[5] = {99, 87, 66, 55, 101};

for (int i = 1; i < 4; i++)

cout << numbers[i] << " ";

a)

99 87 66 55 101

b)

87 66 55 101

c)

87 66 55

d)

Nothing. This code has an error.

13.

An array of string objects that will hold five names would be declared with which of the following statements?

a)

string names[5];

b)

string names(5);

c)

string names 5;

d)

String[5] = names;

14.

Given the following declaration, where is the value 15 stored in the nums array?

int nums[] = {83, 15, 57, 87, 80}

a)

nums[0]

b)

nums[1]

c)

nums[2]

d)

nums[3]

15.

What will the following code display?

int numbers[5] = { 66, 55, 101, 99, 87};

for (int i = 2; i < 5; i++)

cout << numbers[i] << " ";

a)

87 101 99 87

b)

101 99 87

c)

66 101 87

d)

Nothing. This code has an error.