Computer Science, asked by jaslinal, 10 months ago

two points to compare scalar variable and array

Answers

Answered by fazaltraders2929
0

Array holds multiple values, whereas an ordinary variable hold a single value. 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).

Similar questions