English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

In one paragraph of 4-8 sentences, describe the use and purpose of arrays. Also, address the correct syntax for arrays.

2007-11-28 00:47:30 · 4 answers · asked by CC 2 in Computers & Internet Programming & Design

4 answers

Try this link.

2007-11-28 01:21:53 · answer #1 · answered by AnalProgrammer 7 · 0 0

hello wanda,

I hope the following helps.

An array in c++ is a data structure composed of one or more instances of the same data type, whether they are native data types to C++ or user-defined. Although they can be re-dimensioned, arrays' use is mainly for containing a pre-defined quantity of the same element/data type. It should be noted that they occupy a contiguous memory area and due to such can be accessed via indexing or via pointer-like methods. They however, have the disadvantage of not being able to save more than the maximum indexes they have and should the data be saved on to them be smaller in size than the maximum length they can handle, the unused space becomes wasted space since it cannot be used elsewhere. More importantly, an array in C++ uses the stack ( a very limited memory resource in a computing system ) which discourages developers from using arrays for huge memory allocation. An array index in C++ always starts with 0.

The syntax for an array declaraion is :
[][index_x];

Example :
int test[5]; /* single dimension array */
int test[5][6][6]; /* multi-dimensional array */

tydef user_type {
char *name;
int blood_type;
}BloodType;
BloodType users[20]; /* a non-native data type array */

I hope this helped you :) See the sites below for further reading :)

2007-11-28 10:08:47 · answer #2 · answered by GorbanZus 3 · 0 0

sounds like you need another 4-8 sentences explanation like last time :-)

a 1D array normally has only one use and that is for storing data or a string. it does not have any sort of structure in it; it's just for storing data. 2D arrays are different. they are more flexible

overall an array is a collection of data of the same type (note the SAME TYPE). it can contain pointers to different data or structures. arrays allow for multiple storage instead of declaring lots of names for each variable, you can declare an array of that type with a single name and with a specific or dynamic size. another use of array is for the easy stepping through data. array since it has a block of memory allocated to it, can easily step through the array, and access the data looked for. this allows less space used and processing time.

2007-11-28 10:15:56 · answer #3 · answered by colo 3 · 0 0

arrays just serve for the purpose of declaring many related data elements of same type. Instead of having to declare a varibla for each data value, you can just put them in a single thing and also in a very related way.
the syntax is as follows:
data-type name[size];
example:
int rooms[20];

2007-11-28 09:25:40 · answer #4 · answered by boxer111 3 · 0 0

fedest.com, questions and answers