One-dimensional arrays in C ++

2

What are the one-dimensional arrangements for?

int Temp[12];
    
asked by Daniel Contreras 10.04.2018 в 16:08
source

2 answers

2
  

What are the one-dimensional arrangements for?

What they serve for will depend on the use they are given. Because of their characteristics, they can be useful in different contexts.

Features.

  • Store data of a certain type contiguously in memory.
  • They are considered a added , although the type stored does not be it.
  • Require that the stored type be buildable by default .
  • Automatically drop pointer to the stored type.
  • The name of the array is equivalent to a pointer to the first element of it, being able to apply pointer arithmetic.

Other things to consider.

  • It is possible that a one-dimensional array does not fit your needs, C ++ offers other data containers that you might want to take a look at, see this thread for more information.
  • With some arithmetic you can simulate a multidimensional array using a one-dimensional array, see this thread for more details about it.
answered by 10.04.2018 в 16:44
1

In the one-dimensional Arrays we can access any element of this without having to consult previous or subsequent elements, this by using an index for each element of the array that gives us its relative position.

int miarreglo[10]
for(int i=0;i<10;i++)
    miarreglo[i]=i*10;

cout<<miarreglo[5]; //50
    
answered by 10.04.2018 в 16:16