Thursday, May 5, 2011

Array in C++

Definition Arrays
Array is a type of structured data in the form of a number of similar data (same data type), whose numbers remain and be given a specific name.
Array elements arranged in rows and can be accessed at random in the memory.
Array has an address that besebelahan / adjoining dependent width data types.
Array can be an array of 1 dimension, 2 dimensions, even n-dimensional.
The elements array of the same data and can contain the same or different.

Accessing array elements
Array elements can be accessed by the program using a particular index by random or sequential
Charging and collection value at a particular index can be done by setting the value or returns the value of the index in question.
In C, there is no error handling to the limit value of the index, whether the index would be in the index array that is defined or not. It is the responsibility of the programmer. So if the programmer to access the index is wrong, then the resulting value will be different or damaged due to accessing memory address that is not appropriate.


Initialize the array:

Initialize array same as the initial value
array at the time defined.

int value [6] = {8,7,5,6,4,3};
can be simplified to become:
int value = {8,7,5,6,4,3};
 

Description: The example above means that you reserve a space in computer memory as much as 6 place with an index of 0-5, where the index into-0-value 8, to-1 worth 7, etc., and all elements of type integer data.
Note: To provide niai 0 against all elements of the array at the time defined, you can assign the initial value 0 on the first element. For example:
Int temp [100] = {0};
Will provide the results of zero value of the subscript value of 0 to 99.


Excellence array:
-Array is suitable for random access. Any element in the array can be referenced directly without going through the other elements.
-If you are in a location element, it is very easy to drill down to the neighboring elements, both elements of the predecessor or successor element
-If the array elements are the values ​​of independent and all must be maintained, then the use of highly efficient storage

Weaknesses array:

-Array must be of type-homogenous. We can not have arrays in which one element is a character, another element numbers, and other elements are other types
-Not efficient in memory usage
-Arresting a lot of computing time
-On an application, the static representation is not possible

No comments:

Post a Comment