answersLogoWhite

0


Best Answer

Depends on your language. Assuming java: If you make it an Object[] then it can contain any object

For primitive types you must either make a primitive type array, ie double[], char[] which can contain only those primitives, or creater an Object[] and use primitive wrapper objects ie java.lang.Integer etc.

User Avatar

Wiki User

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

Wiki User

11y ago

That really depends on the programming language. In the case of Java, for example, you have to specify the type of any array you create. However, if you declare some classname as the type, you can also use subtypes, i.e., inherited classes. Specifically, if you declare an array of type "Object", you can then store objects of any type, since all classes inherit from "Object".

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How many data types can the elements of an array have?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why should all of the elements in an array have the same data type?

Yes all of the elements in array must be the same type. Because when you define an array you specify the type of data it will hold. Examples in C: int IntArray[10]; // an array of 10 integers double FloatArray[20]; // array of 20 double floating point numbers


What is an arrey and how many types of arrey in details?

An array is a data type that describes a collection of ordered variables and types of arrays include vector arrays and matrix arrays.


What are arrays?

Array data structure, an arrangement of items at equally spaced addresses in computer memoryArray data type, used in a programming language to specify a variable that can be indexedAssociative array, an abstract data structure model that generalizes arrays to arbitrary indicesor various kinds of the above, such asBit array or bit vectorDynamic array, allocated at run timeParallel array of records, with each field stored as a separate arraySparse array, with most elements omitted, to store a sparse matrixVariable-length arrayRagged (jagged) array, where the rows have different lengths individuallyor various related concepts:Array processor, a computer to process arrays of data (not to be confused with a processor array)Array programming, using matrix algebra notation in programs (not the same as array processing)Array slicing, the extraction of sub-arrays of an arrayAPL (programming language)or also:Video Graphics Array (VGA), a display adapter and video format, and many variants thereof (EVGA, FWVGA, QVGA, QXGA, SVGA, SXGA, SXGA+, TXGA, UVGA, XGA, XGA+, ...)


How do you insert and delete elements from an array in dynamic memory allocation?

To delete an array element you must create a new array with one less element, then traverse both arrays, copying elements from one to the other, but skipping over the element you want to delete. Once all elements are copied, you can release the original array. A slightly more efficient method would be to move the empty element to the end of the array and then re-allocate the entire array with one less element, using the realloc() command. To insert a new element, create a new array with one additional element. Then traverse both arrays, copying elements from one to the other. The original array can then be deleted, and the new data can be placed at the end of the new array. Again, the realloc() command is the most efficient method of doing so. However, if the array must be sorted, you must compare the new data with each element prior to copying, and insert at the appropriate point. Once inserted, the remaining elements can be copied into place and then the original array can be released. Due to the reallocation and copying of elements, this approach is highly inefficient. You can alleviate some of the re-allocations by allocating several empty elements at a time, and keeping track of how many empty elements there are available for insertions. This can be achieved by keeping all empty elements at the end of the array, and maintaining a count of those elements. To delete an existing element, shunt data to the right one place to the left to remove the gap. And if the number of empty elements exceeds a given minimum, re-allocate the array to remove redundancy. Although this is a better approach, it is still quite inefficient, particularly if the array is large. If the array is small and there are few insertions and deletions, then it probably won't matter too much, but for larger arrays with many insertions and deletions to cater for, a far better approach would be to use a linked list. This makes better use of memory, as the list can expand and contract dynamically without the need to copy any elements (or nodes) whatsoever. Some additional memory is required to maintain the links between the nodes but, unlike an array, no memory is ever wasted.


Difference between array processor and multiprocessor?

an array processor can handle multiple data elements simultaneously,in a parallel fashion, but a multiprocessor handle multiple processes simultaneously which may include more than one data element in each process... An array procesor is optimized for array operations, has its own set of instructions, large memory block moves, logical operations on many array elements, etc and may itself be multi-processor or massively parallel. It has an interface where a host loads memory locations with the array to be processed (or perhaps a data file), then the array processor uses its specialized structure to do what was asked of it on the array, then tell the host is done and the result may be found in memory locations or perhaps a data file. Many of the jobs supercomputers do are array operations, the specialized capabilities can cost thousands of dollar per CPU second but they can do array operations that might take years for slower general purpose computers. An array procesor can also be smaller, a graphics processor handling the video display is an array processor. A typical operation is move the image to the right, move all the pixels to the right.. A general purpose computer may be multi-processor (Intel's multi-core).

Related questions

Why should all of the elements in an array have the same data type?

Yes all of the elements in array must be the same type. Because when you define an array you specify the type of data it will hold. Examples in C: int IntArray[10]; // an array of 10 integers double FloatArray[20]; // array of 20 double floating point numbers


What is an arrey and how many types of arrey in details?

An array is a data type that describes a collection of ordered variables and types of arrays include vector arrays and matrix arrays.


What are arrays?

Array data structure, an arrangement of items at equally spaced addresses in computer memoryArray data type, used in a programming language to specify a variable that can be indexedAssociative array, an abstract data structure model that generalizes arrays to arbitrary indicesor various kinds of the above, such asBit array or bit vectorDynamic array, allocated at run timeParallel array of records, with each field stored as a separate arraySparse array, with most elements omitted, to store a sparse matrixVariable-length arrayRagged (jagged) array, where the rows have different lengths individuallyor various related concepts:Array processor, a computer to process arrays of data (not to be confused with a processor array)Array programming, using matrix algebra notation in programs (not the same as array processing)Array slicing, the extraction of sub-arrays of an arrayAPL (programming language)or also:Video Graphics Array (VGA), a display adapter and video format, and many variants thereof (EVGA, FWVGA, QVGA, QXGA, SVGA, SXGA, SXGA+, TXGA, UVGA, XGA, XGA+, ...)


What is an arrays in c?

array is collection of many data


How do you insert and delete elements from an array in dynamic memory allocation?

To delete an array element you must create a new array with one less element, then traverse both arrays, copying elements from one to the other, but skipping over the element you want to delete. Once all elements are copied, you can release the original array. A slightly more efficient method would be to move the empty element to the end of the array and then re-allocate the entire array with one less element, using the realloc() command. To insert a new element, create a new array with one additional element. Then traverse both arrays, copying elements from one to the other. The original array can then be deleted, and the new data can be placed at the end of the new array. Again, the realloc() command is the most efficient method of doing so. However, if the array must be sorted, you must compare the new data with each element prior to copying, and insert at the appropriate point. Once inserted, the remaining elements can be copied into place and then the original array can be released. Due to the reallocation and copying of elements, this approach is highly inefficient. You can alleviate some of the re-allocations by allocating several empty elements at a time, and keeping track of how many empty elements there are available for insertions. This can be achieved by keeping all empty elements at the end of the array, and maintaining a count of those elements. To delete an existing element, shunt data to the right one place to the left to remove the gap. And if the number of empty elements exceeds a given minimum, re-allocate the array to remove redundancy. Although this is a better approach, it is still quite inefficient, particularly if the array is large. If the array is small and there are few insertions and deletions, then it probably won't matter too much, but for larger arrays with many insertions and deletions to cater for, a far better approach would be to use a linked list. This makes better use of memory, as the list can expand and contract dynamically without the need to copy any elements (or nodes) whatsoever. Some additional memory is required to maintain the links between the nodes but, unlike an array, no memory is ever wasted.


Difference between array processor and multiprocessor?

an array processor can handle multiple data elements simultaneously,in a parallel fashion, but a multiprocessor handle multiple processes simultaneously which may include more than one data element in each process... An array procesor is optimized for array operations, has its own set of instructions, large memory block moves, logical operations on many array elements, etc and may itself be multi-processor or massively parallel. It has an interface where a host loads memory locations with the array to be processed (or perhaps a data file), then the array processor uses its specialized structure to do what was asked of it on the array, then tell the host is done and the result may be found in memory locations or perhaps a data file. Many of the jobs supercomputers do are array operations, the specialized capabilities can cost thousands of dollar per CPU second but they can do array operations that might take years for slower general purpose computers. An array procesor can also be smaller, a graphics processor handling the video display is an array processor. A typical operation is move the image to the right, move all the pixels to the right.. A general purpose computer may be multi-processor (Intel's multi-core).


How arrays must be handled in c plus plus?

If the array is static it can declared in the structure itself: struct myArrayTag { int num[12]; // array of 12 integers (e.g., 48 bytes). } myArray; If it is dynamic then you must use a pointer and allocate the array outside the structure. You should also maintain a variable in the structure to keep track of how many elements the array currently has: struct myBufferTag { int * array; // Pointer to array of integers. int size; // Size of array (number of elements); } myBuffer;


What is the algorithm using c to delete duplicate elements from an array?

To detect the duplicate, you will have to write a nested loop that compares each element with all the previous elements.To actually delete the duplicate, once you find it, you have to move over all the elements after the duplicate. If the order of the elements doesn't matter, it is faster to just move the LAST array element, overwriting the duplicate element. Use a variable to keep track how many elements of the array are "usable". For example, if your array had 10 elements, and you delete 1, the array size will still be 10... but (after moving the elements over) only 9 of those elements have useful information.


How many bytes occupied for arrays?

It all depends on the length and data type of the array...


How many minerals on the periodic table are compounds?

The periodic table in as array of elements and not minerals or compounds.


How many exchange needed for reverse an array of n elements?

the integer of 1/2 n


How many kinds of search in data structure?

array, file, record, table, the tree and so on