answersLogoWhite

0


Best Answer

Array is the set of an multiple values where as variable can store single value at a time.

• The difference between the definition of array and ordinary variable is the, array is always declared, initialized, and accessed using subscript whereas ordinary variable do not have any subscript.

• The syntax for ordinary variable definition is data_type v1, v2, ….;

• And the syntax for array variable is data_type v1[N1],v2[N2],…; where v1,v2 are name of variable and N1, N2 are the integer constants indicating the maximum size of array.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

An array is a collection of variables of the same type. Variable is a single value, while array is a collection.

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

An array is a collection of variables of the same type. For example:

int x[10];

defines 10 integer variables at consecutive memory locations starting with x[0] and ending with x[9].

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

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).

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

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 programing language.

for example char firstcharacter; (a variable) would store only one letter, while char firstarry [11]; (an array) would store up to a 10 letter word (due to the null character on the end)

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

ordanry variable store one value at a time.

arrays are used for storing more than one value at a time in a single variable name

ordanry variable doesnt have subscript.

array must have subscript

syntax for ord. variable Datatype v1,v2......

syntax for array variable Datatype v1[n1],v2[n2].....

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

An ordinary variable holds a single value; an array variable holds multiple values.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

COPACABANA

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between array element and variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is an individual storage location in an array?

swag variable


What is the difference between an array shift and unsetting a variable in PHP?

By shifting the values in an array, you are moving a key's value to the previous key. The very first key's value is obliterated. By shifting all values in the array, all keys will have a value of NULL. Unsetting a variable is entirely different -- performing a variable unsetting causes the variable to have a value of NULL, as if it was never set.


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, myArray[0], myArray[5]. The subscript can also be a variable, for example, myArray[i], making it easy to write a loop that processes all the elements of an array, or some of them, one after another.


How can you search an array element in a file?

Logic to search element in array Input size and elements in array from user. ... Input number to search from user in some variable say toSearch . Define a flag variable as found = 0 . ... Run loop from 0 to size . ... Inside loop check if current array element is equal to searched number or not. To learn more about data science please visit- Learnbay.co


How do you use subscripts with an array?

An array is a list of several related elements. You use the subscript to specify which element you want to access. For example, in Java you might have an array called myArray, with 10 elements (numbered from 0 to 9); myArray[3] would access the fourth element in the array. A variable may be used instead of a constant.

Related questions

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 difference is that a program can iterate over an array without the programmer knowing the original size of the array or explicitly which member to access.


What is an individual storage location in an array?

swag variable


What is the difference between an array shift and unsetting a variable in PHP?

By shifting the values in an array, you are moving a key's value to the previous key. The very first key's value is obliterated. By shifting all values in the array, all keys will have a value of NULL. Unsetting a variable is entirely different -- performing a variable unsetting causes the variable to have a value of NULL, as if it was never set.


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, myArray[0], myArray[5]. The subscript can also be a variable, for example, myArray[i], making it easy to write a loop that processes all the elements of an array, or some of them, one after another.


How can you search an array element in a file?

Logic to search element in array Input size and elements in array from user. ... Input number to search from user in some variable say toSearch . Define a flag variable as found = 0 . ... Run loop from 0 to size . ... Inside loop check if current array element is equal to searched number or not. To learn more about data science please visit- Learnbay.co


How do you use subscripts with an array?

An array is a list of several related elements. You use the subscript to specify which element you want to access. For example, in Java you might have an array called myArray, with 10 elements (numbered from 0 to 9); myArray[3] would access the fourth element in the array. A variable may be used instead of a constant.


What is the difference between subscript and subscripted variable in c plus plus?

Subscripts are used to identify the elements in an array, where the first element has subscript 0. Thus an array of n elements has subscripts in the range 0 to n-1. Each element may itself be an array, thus allowing multi-dimensional arrays. The subscript may be a constant or a variable. However, when declaring a static array, the subscript must be a constant. Constants include literal constants as well as named constants. A subscripted variable is simply an array or a datatype that can be divided into an array. For instance, a 32-bit int can be treated just as if it were an array of two 16-bit shorts or four 1-byte chars. Thus in the 32-bit int array, int i[10], i is a subscripted variable where i[0] is the first integer and i[9] is the last. If we then say char*c=&i, c would allow us to treat i as if it were a subscripted variable with 40 char elements (c[0] to c[39]).


What is difference between key and index in php arrays?

A key is the name of a variable in an array ($array["key"]) and the index is the position it's at ($array = ["key" => 0], the index would be 0). Keys and indices are the same if the array is not associative though ($array = [true], the key holding the value true is named 0 and is at index 0).


How do you calculate array elements value?

You don't need to calculate an array element's value. An array element is a variable and like any variable you can access its value directly. There is nothing to calculate: int a[5] {0, 2, 4, 6, 8}; int x = a[2]; // x=4 The only thing that really needs calculating is the index of the element you wish to access. If you know the index, then there's nothing to calculate.


Index of an element in array?

An array is a group of related elements, with a common variable name. The index is a number that indicates the position of an element within an array: the 1st. element, the 2nd. element, etc. (many languages start counting at zero).


How do you access 2D array elements by using single variable?

int main() { int array[3][3]; int i; for(i=0; i <9;i++) { printf("the element is %d\n", array[i/3][i%3]); } return 0; }


What is the relationship between the value of the subscript and the value of the array element in c?

You can access the array-element via index (or subscript), but it is not possible the other way around.