answersLogoWhite

0


Best Answer

Computer memory is linear so a one dimensional array can be mapped on to the memory cells in rather straight forward manner.To find the actual address of an element one needs to subtract one from the position of the desired entry and then add the result to the address of the the first cell in the sequence.Having said that therefore it is necessary to know the starting address of the space allocated to the array and the size of the each element, which is same for all the elements of an array.The the location of the Ith element would be B+I*S

where B is the base address(Starting address of the array) and S is the size of each element of the array.

User Avatar

Wiki User

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

Wiki User

12y ago

The elements of an array are stored in consecutive memory in a computers internal memory.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

They are stored in consecutive memory locations.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How are elements of an array stored in memory?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What are the different types of array explain with examples?

There are two main types of array:1) Single dimensional array: These are arrays for which only one index is required to access the element stored in an array. They are stored in a contiguous memory location.Eg:int arr[10];//declarationarr[7] = 7;//initialization2) Multidimensional array: These are arrays for which more than one index is required to access the element stored in a specific location in the array. These are stored in a contiguous memory location row-by-row.Eg:int arr[5][5];//two dimensional arrayint arr[5][5][5];//three dimensional array


Why multidimensional array element access using indirection operator?

The number of dimensions is immaterial. All arrays are implemented as a one dimensional array. A multidimensional array is simply an array where every element is itself an array. The only thing actually known about any array is that its name is a reference to the start address. Unlike an ordinary (non-array) variable, the elements in the array do not have names, we can only refer to them by their memory offsets from the start of the array. As such, in order to obtain the values stored at those offsets, we must dereference them. While the subscript operator gives us notational convenience, it's easy to forget that there's actually pointer arithmetic and dereferencing going on behind the scenes.


What is faster access the element in an array or in a list?

Array is always faster to read from disk/access any element in the array is quicker since elements in a array are stored in contiguous location in the memory, you need the pointer to the head or 0th element in the array and then it much quick to navigate to the next on index based. But you need to know INDEX of the element for best results List (say linked list) will be slower since not always elements are stored in contiguous location in the memory as well it involves a function call which is can be assembler/cpu expensive. However getting an individual object from an array is faster if you know the index of the object. Walking through a linked list is faster than walking through an array, if you use a non-recursive algorithm. --Vinay Solanki


What restriction must be satisfied by all of the data items represented by an array?

An array is a group of related items that share a common name.All these elements are stored consecutively. An array must be declared before its use in the program. Array size must be specified All Array elements must be assigned to any value for assignment the value. Partial initialization of elements of an array is not allowed. Size must be integer constant enclosed within square brackets The name of the array indicates starting address of an array. Each individual element of array is accessed by a subscript.


The elements in an array must be of the same basic data type but why must they be stored in contiguous memory?

An array is nothing more than a block of contiguous memory addresses divided into one or more units of equal length. We call these units elements. As a result, all elements of an array must be allocated contiguously. Other than padding for memory alignment purposes, an array offers the most compact storage for multiple elements of the same type. And because the elements are allocated contiguously, it is trivial to traverse the array from one element to the next using nothing more than a pointer variable of the same type as the array. Each increment or decrement of the pointer increases or decreases the address by 1 element. The array suffix operator [] does the same thing, except the index is a zero-based offset from the start of the array. The first element is index 0 because it is 0 elements from the start of the array while the nth element is found at index n-1. When we create an array we have the choice of storing the objects themselves in the array or storing a pointer to the objects. With the latter, the objects need not be allocated contiguously, however we consume more memory because the array of pointers consumes additional memory that we wouldn't need to consume were all the objects allocated in the array itself. We also have the additional cost of dereferencing those pointers in order to access the objects being referred to. However, arrays of pointers are advantageous when the objects are larger than a pointer (in bytes) or are of polymorphic type. Copying or moving a large object in memory is more expensive than copying or moving a pointer, so if we need to sort an array of large objects, an array of pointers is generally more efficient despite the indirection. But with polymorphic types we have to use pointers because polymorphic types are not guaranteed to be the same length so we must store a pointer to the common base type if we wish to retain polymorphic behaviour.

Related questions

What are the different types of array explain with examples?

There are two main types of array:1) Single dimensional array: These are arrays for which only one index is required to access the element stored in an array. They are stored in a contiguous memory location.Eg:int arr[10];//declarationarr[7] = 7;//initialization2) Multidimensional array: These are arrays for which more than one index is required to access the element stored in a specific location in the array. These are stored in a contiguous memory location row-by-row.Eg:int arr[5][5];//two dimensional arrayint arr[5][5][5];//three dimensional array


How to display the content of memory address stored in an element of an array?

void *array[2]; printf ("array[%d]=%p\n", i, array[i]);


A byte stored in AL is present in array of 10 bytes stored in the memory Store the number of occurrences of the byte in register AH?

Of 10 bytes simply stored in the memory? YAWN...


What is single dimentional?

A single dimension array is an array with one dimension. It is a collection in memory of one or more elements of the same type. int array[100]; declares an array of int's of size 100 elements. The elements are referenced as array[0], the first one, through array[99], the last one.


Why array is a primitive data structure?

An array is a primitive data structure because all elements are stored in contiguous memory. Unlike complex structures like lists and trees, elements are not stored in nodes that provide structural information. Structure is created from the elements themselves, insofar as each element is exactly the same length (in bytes) thus it is trivial to access an element in constant time from its zero-based index alone.


What an array?

An array is an aggregate of data elements of the same type. Arrays are allocated in contiguous memory. An element of an array can be another array type, also known as a multi-dimensional array.


What is array in program?

An aggregate of elements of the same type that occupy contiguous memory.


What is sparse array?

A sparse array (or sparse matrix) is an array where only a few elements are actually allocated storage space in memory, the unallocated elements are forced to zero for calculation purposes. Such arrays usually use pointers to reference the storage for the allocated elements.


How is a string stored in array?

The characters are stored in successive elements of the array with a nul (0) in the element after the last character of the string. Remember the array storing a string in C must be at least one element longer than the longest string to be stored in it to allow space for this nul (0) character.


What is an array of 5 x 46?

An array is a contiguous memory allocation divided into one or more elements of equal size. A 5 x 46 array is an array of 5 elements where each element is another array of 46 elements. In other words it is an array of arrays. We can the array a two-dimensional array because it has 5 elements in one dimension (the rows) and 46 in the other dimension (the columns). If an individual column element is 4 bytes long, then each row element consumes 46 x 4 = 184 bytes of memory while the entire array consumes 5 x 184 = 920 bytes in total. We can also think of the entire array as being a one-dimensional array of 5 x 46 = 320 elements of 4 bytes each.


Why multidimensional array element access using indirection operator?

The number of dimensions is immaterial. All arrays are implemented as a one dimensional array. A multidimensional array is simply an array where every element is itself an array. The only thing actually known about any array is that its name is a reference to the start address. Unlike an ordinary (non-array) variable, the elements in the array do not have names, we can only refer to them by their memory offsets from the start of the array. As such, in order to obtain the values stored at those offsets, we must dereference them. While the subscript operator gives us notational convenience, it's easy to forget that there's actually pointer arithmetic and dereferencing going on behind the scenes.


How can two single dimensional array values be stored in a third single dimensional array?

You need to create a new array with enough elements to cater for both arrays. Thus if the first array has 10 elements and the second has 5, you must create a 15 element array to store both. You then copy elements from the first array into the third and immediately follow with the elements from the second. Note that the first two arrays must be of the same type. You cannot combine an array of numeric values with an array of strings, for instance.