What is the difference between an array and variable?

already exists.

Would you like to merge this question into it?

already exists as an alternate of this question.

Would you like to make it the primary and merge this question into it?

exists and is an alternate of .

Traditional wisdom would say that an array holds multiple values, whereas an ordinary variable hold a single value.

While this is not false per se, it is only really true in certain cases: it is true when the elements of the array are treated as individual entities, and when the variable is a simple scalar variable such as an int.

However, a variable can also be a structure or a union, capable of holding multiple values, and an array can be thought as a single variable. For example, in the C programming language, it is common to define temporary storage for an alphanumeric string through an array of characters. While some algorithms process each character individually, the data held in the array may only be meaningful as a whole. Note that you would also call 'buffer' in the following example a variable:


void example(void) {
char* buffer[MAX_SIZE];
...
}

It is not generally right to distinguish between a variable and an array. You'd be comparing apples with pears. Arrays are primitive aggregate data structures and belong into the same category as structures and unions. These are aggregates, because they can contain more than one scalar element. Scalars, in contrast, are atomic types of the language, types such as int, char, enum xyz, etc, in the C programming language.

Variables can be contrasted to constants.

Arrays can be contrasted to scalars (e.g. int), or to other aggregates (e.g. struct) or data structures of higher order (e.g. lists).
1 person found this useful

What is the difference between an array element and a variable?

Array elements are all members of the same variable, indexed in a logical manner. variables are distinct objects which must be referred to distinctly.. The main functional di (MORE)

What is the difference between an array and a variable?

Variables such as int, char, and float are simply one number/character. And array is a collection of variables, sort of like what would be called a string in another programin (MORE)

What is array What is difference between array and simple variable?

An array stores several values - for example, several numbers - using a single variable name. The programmer can access the individual values with a subscript, for example, my (MORE)