Home / The science / Mathematics / How to make an array

How to make an array

/
92 Views

How to make an array</a>

An array is an ordered structure that contains data of a certain type. There are one-dimensional (linear) arrays and multidimensional data arrays.

Usually, a one-dimensional array can include only the same type of elements.

As a rule, you can access the array by its name, which is the address of the array in memory.

In C and C ++, an array can contain both standard data types and created structures, classes, and other elements.

Instructions

    1

Determine the type of data whose elements youIs required to be stored in an array. When specifying numeric data, the types are usually used: int, double, float, string - char. To create a one-dimensional array, write a string like this: int Massiv1 [5].

    2

When working with a two-dimensional array, its creationLooks like this: char Massiv2 [3] [4]. In the first case, the variable Massiv1 will contain 5 elements of type int. In the second case, Massiv2 points to a two-dimensional array that has 3 rows, 4 columns, and contains elements of type char.

    3

If you need to set a linear arrayOf unknown size, write down a similar form: char * Massiv3 []. In this case, a hard-coded memory size will not be allocated to the array. The variable Massiv3 will be a null pointer, which must be initialized. For this variable is immediately assigned the value: char * Massiv3 [] = {"First element", "Second element", "Third element"}.

    4

To create an array containing objectsStructure, first set the type of this structure. For example, there is a structure of the form: struct ASD {int a const char * b-}. Here we get a new type of ASD containing data of two standard types. Then you can use it to create new arrays. And the arrays will also contain elements with two two standard types: int and a pointer to the string char.

    5

Create an array of elements of the developed structure. To do this, imagine the new structure as a type, and write down the expression: ASD Massiv4 [6]. Here ASD is a type, Massiv4 is the name of the created array containing 6 ASD type elements. Similarly, an array is created for any possible data types.

How to make an array

How to make an array Was last modified: June 21st, 2017 By Taxnievr
It is main inner container footer text