What do you mean by an Array?

Array

An array is a data structure that contains a group of elements. Typically these elements are all of the same data type, such as an integer or string. Arrays are commonly used in computer programs to organize data so that a related set of values can be easily sorted or searched.

For example, a search engine may use an array to store Web pages found in a search performed by the user. When displaying the results, the program will output one element of the array at a time. This may be done for a specified number of values or until all the values stored in the array have been output. While the program could create a new variable for each result found, storing the results in an array is much more efficient way to manage memory.

The syntax for storing and displaying the values in an array typically looks something like this:

arrayname[0] = "This ";
arrayname[1] = "is ";
arrayname[2] = "pretty simple.";

print arrayname[0];
print arrayname[1];
print arrayname[2];

The above commands would print the first three values of the array, or “This is pretty simple.” By using a “while” or “for” loop, the programmer can tell the program to output each value in the array until the last value has been reached. So not only do arrays help manage memory more efficiently, they make the programmer’s job more efficient as well.

 

Image result for What do you mean by an Array?

Add Comment


  • 3 Answer(s)
    • An array is a collection of data items, all of the same type, accessed using a common name.
    • A one-dimensional array is like a list;  A two dimensional array is like a table;  The C language places no limits on the number of dimensions in an array, though specific implementations may.
    • Some texts refer to one-dimensional arrays as vectors, two-dimensional arrays as matrices, and use the general term arrays when the number of dimensions is unspecified or unimportant.
    • Initializing Arrays

        • Arrays may be initialized when they are declared, just as any other variables.
        • Place the initialization data in curly {} braces following the equals sign.  Note the use of commas in the examples below.
        • An array may be partially initialized, by providing fewer data items than the size of the array.  The remaining array elements will be automatically initialized to zero.
        • If an array is to be completely initialized, the dimension of the array is not required.  The compiler will automatically size the array to fit the initialized data.  ( Variation:  Multidimensional arrays – see below. )
        • Examples:
              int i =  5, intArray[ 6 ] = { 1, 2, 3, 4, 5, 6 }, k;
              float sum  = 0.0f, floatArray[ 100 ] = { 1.0f, 5.0f, 20.0f };
              double  piFractions[ ] = { 3.141592654, 1.570796327, 0.785398163 };
    Answered on February 19, 2019.
    Add Comment

    Array:

    Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

    Instead of declaring individual variables, such as number0, number1, …, and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and …, numbers[99] to represent individual variables. A specific element in an array is accessed by an index.

    All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.

    Arrays in C

    Answered on February 21, 2019.
    Add Comment
    An array is a data structure that contains a group of elements. Typically these elements are all of the same data type, such as an integer or string. Arrays are commonly used in computer programs to organize data so that a related set of values can be easily sorted or searched.

    For example, a search engine may use an array to store Web pages found in a search performed by the user. When displaying the results, the program will output one element of the array at a time. This may be done for a specified number of values or until all the values stored in the array have been output. While the program could create a new variable for each result found, storing the results in an array is much more efficient way to manage memory.

    The syntax for storing and displaying the values in an array typically looks something like this:

    arrayname[0] = "This ";
    arrayname[1] = "is ";
    arrayname[2] = "pretty simple.";

    print arrayname[0];
    print arrayname[1];
    print arrayname[2];

    The above commands would print the first three values of the array, or “This is pretty simple.” By using a “while” or “for” loop, the programmer can tell the program to output each value in the array until the last value has been reached. So not only do arrays help manage memory more efficiently, they make the programmer’s job more efficient as well.

    Updated: October 17, 2007

    Cite this definition:

    Answered on February 21, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.