Home WHAT IS... AND HOW DO...? INITIALIZING ACCESING ELEMENTS FROM ONE- DIMENSIONAL ARRAYS ADING,INSERT AND DELETE PROBLEMS SOLVED Test
What is... and How do..?

What is a one-dimensional array?


The one-dimensional array is a data structure that is assigned a name. It consists of a collection of elements of the same type, continuously placed in memory. Elements can be accessed individually by indexes. All elements have a predecessor (except the first element) and a successor (except the last element).

How do I declare a one-dimensional array?

To declare a one-dimensional array you need 3 properties: its type, name and size. Some examples:

 int V[25]; // an array that holds 25 integers

 char s[40]; // an array that holds 40 characters

 float x[30]; // an array that holds 30 real numbers

An element of an array can be used like any other variable. To access an element in an array, you must refer to its index, enclosed in square brackets. An important aspect is the fact that you can only perform operations on a single element, you cannot modify the entire painting at once.

One dimensional array = vector?

An elementary mistake that all teachers accept is the following: they allow students to call this data structure "vector" - but this is totally wrong.

Because once a one-dimensional array is declared - you can no longer change the total number of elements stored in it. While in a vector, the total number of elements varies during the running of the program.