How to make the massif

How to make the massif

Articles Hits: 65

The massif represents the ordered structure containing data of a certain type. There are one-dimensional (linear) massifs and multidimensional data arrays. Usually one-dimensional massif can include only the same elements. As a rule, access to the massif can be got by its name which is the massif address in memory. In the C and C language ++ the massif may contain, both standard types of data, and the created structures, classes and other elements.

Instruction

1. Define type of data which elements you need to store in the massif. At the indication of numerical data types are usually used: int, double, float, line – char. For creation of the one-dimensional massif write down a line of a look: int Massiv1 [5].

2. During the work with the two-dimensional massif, its creation looks so: char Massiv2 [3][4]. Massiv1 variable will contain 5 int elements in the first case. In the second case - Massiv2 indicates the two-dimensional massif having 3 lines, 4 columns and containing char elements.

3. If you need to set the linear massif of the unknown size, write down a similar form: char * Massiv3 []. In this case under the massif strictly given size of memory will not be allocated. Massiv3 variable will be the empty index which needs to be initialized. For this purpose the value is appropriated to a variable at once: char * Massiv3 [] = {""First element" ", " "Second element" ", " "Third element"" }.

4. For creation of the massif containing objects of structure at first set type of this structure. For example, there is a structure of a look: struct ASD {int a; const char * b; }. Here the new ASD type containing data of two standard types turns out. Further it can already be used for creation of new massifs. And massifs will also contain elements with two two standard types: int and the index for the line char.

5. Create the massif of elements of the developed structure. For this purpose present new structure how type, and write down expression: ASD Massiv4 [6]. Here ASD is type, Massiv4 is a name of the created massif containing 6 ASD elements. The same way there is a creation of the massif for any possible types of data.

Author: «MirrorInfo» Dream Team

Print