Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use arrays in C++

Shulou Source: shulou.com Published: 2022-06-01 17:30:40 09月14日 Update

This article mainly introduces the relevant knowledge of "how to use arrays in C++". The editor shows you the operation process through an actual case. The method of operation is simple, fast and practical. I hope this article "how to use arrays in C++" can help you solve the problem.

1 Overview

An array is a collection of data elements of the same type.

Feature 1: each data element in the array is of the same data type.

Feature 2: the array is made up of consecutive memory locations.

2 one-dimensional array 2.1 one-dimensional array definition method

There are three kinds.

1. Data type array name [array length]; 2. Data type array name [array length] = {value 1, value 2, value 3.}; 3. Data type array name [] = {value 1, value 2, value 3 includeusing namespace std;int main.}; # includeusing namespace std;int main () {/ / first definition array int arr [5]; memset (arr, 0, sizeof (arr)); / / initialized to 0, otherwise it is a random number arr [0] = 10; arr [1] = 10; arr [2] = 10 Arr [3] = 10; arr [4] = 10; / / access the array for (int I = 0; I < 5; iTunes +) {cout

Tags: Array data element memory type address two-dimensional sort length jduration method base one-dimensional time space clocked same line content decimal Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MySQL Shulou Tech Info Xiaomi Microsoft