C++ · ОСНОВЫ · LESSON 12

Numbers near

Massive · about 12 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

How it works.

The array stores several values of one type. First place is number 0.

int nums[3] = {2, 4, 6};
Indices
0first1second2third

✦ To see the second number, use the index [1].

STEP 2

Try to understand.

To see the second number, use the index [1].

int nums[3] = {2, 4, 6};
cout << nums[1] << endl;

✦ Compare this to the first one. Then do the cool job yourself.

IN-CLASS PRACTICE

Type the code yourself

Manually type the program from the sample. So you'll remember commands and brackets.

#include <iostream>
using namespace std;

int main() {
    int nums[3] = {2, 4, 6};
    cout << nums[1] << endl;
    return 0;
}
Open the editor for class work
HOMEWORK

Solve it yourself

Create an array of int nums[3] from the numbers 3, 6, 9 and output the third number by index.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework