1. Array Definitions
• Array is a type of structured data in the form of a number of similar data (same datatype), 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.
• Arrays can be an array of 1 dimension, 2 dimensions, even n-dimensional.
• The elements array of the same data and can contain the same value or different.
• Array is a type of structured data in the form of a number of similar data (same datatype), 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.
• Arrays can be an array of 1 dimension, 2 dimensions, even n-dimensional.
• The elements array of the same data and can contain the same value or different.
2. Accessing Array Elements
• The elements of the array can be accessed by the program using a particular indexby random or sequential
• Charging and taking values in a particular index can be done by setting the value orreturns the value of the index in question.
• In C, there is no error handling to the limit value of the index, whether the index wouldbe 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 bedifferent or damaged due to accessing memory address that is not appropriate.
3. Example of one-dimensional array
char letter [9];
int age [10];
int state [2] = {0.1}
arr_dinamis int [] = {1,2,3}
• Signs [] is also called "element to ...". For example, the condition [0] means an array of state elements to zero.
• Arrays are already booked, for example 10 places do not have to fill all of them,could be just filled with 5 elements, either in sequence or not. However, in conditions that are not fully occupied, the place of reservation in the memory still as many as 10places, so places that remain unfilled will be booked and left blank.
• We can not declare a dynamic array without initialization!
Sample arrays
# include <iostream>
# include <conio.h>
void main ()
{int y [] = {1, 2, 7, 4, 5};
int n, r = 0;
for (n = 0, n <5, n + +)
{
r + = y [n];
}
court <<"" <<r;
getch ();}
4. Array 2 Dimension
• two-dimensional arrays are often described as a matrix, is an extension of one-dimensional array.
• If the one-dimensional array consists only of a row and several columns of elements,then the two-dimensional array consisting of several rows and several columns of the same type elements.
• The elements of the array can be accessed by the program using a particular indexby random or sequential
• Charging and taking values in a particular index can be done by setting the value orreturns the value of the index in question.
• In C, there is no error handling to the limit value of the index, whether the index wouldbe 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 bedifferent or damaged due to accessing memory address that is not appropriate.
3. Example of one-dimensional array
char letter [9];
int age [10];
int state [2] = {0.1}
arr_dinamis int [] = {1,2,3}
• Signs [] is also called "element to ...". For example, the condition [0] means an array of state elements to zero.
• Arrays are already booked, for example 10 places do not have to fill all of them,could be just filled with 5 elements, either in sequence or not. However, in conditions that are not fully occupied, the place of reservation in the memory still as many as 10places, so places that remain unfilled will be booked and left blank.
• We can not declare a dynamic array without initialization!
Sample arrays
# include <iostream>
# include <conio.h>
void main ()
{int y [] = {1, 2, 7, 4, 5};
int n, r = 0;
for (n = 0, n <5, n + +)
{
r + = y [n];
}
court <<"" <<r;
getch ();}
4. Array 2 Dimension
• two-dimensional arrays are often described as a matrix, is an extension of one-dimensional array.
• If the one-dimensional array consists only of a row and several columns of elements,then the two-dimensional array consisting of several rows and several columns of the same type elements.
# include <iostream>
# include <conio.h>
int main () {/ / definition array 2dimensi
typedef int matrik32 [3] [2]; / / declare an array of A, B, C
matrik32 A, B, C;
int j, k; / / fill array elements A
for (j = 0, j <3; j + +)
{for (k = 0, k <2; k + +)
{
court <<"A [" <<j <<"]["<< k <<"] =";
cin>> A [j] [k];
}
} court <<endl;
/ / fill array elements B
for (j = 0, j <3; j + +)
{for (k = 0, k <2; k + +)
{
court <<"B [" <<j <<"]["<< k <<"] =";
cin>> B [j] [k];
}
# include <conio.h>
int main () {/ / definition array 2dimensi
typedef int matrik32 [3] [2]; / / declare an array of A, B, C
matrik32 A, B, C;
int j, k; / / fill array elements A
for (j = 0, j <3; j + +)
{for (k = 0, k <2; k + +)
{
court <<"A [" <<j <<"]["<< k <<"] =";
cin>> A [j] [k];
}
} court <<endl;
/ / fill array elements B
for (j = 0, j <3; j + +)
{for (k = 0, k <2; k + +)
{
court <<"B [" <<j <<"]["<< k <<"] =";
cin>> B [j] [k];
}
}
court <<endl; / / summing arrays A and B
for (j = 0, j <3; j + +)
{for (k = 0, k <2; k + +)
{
C [j] [k] = A [j] [k] + B [j] [k];
}
} / / display the sum array
for (j = 0, j <3; j + +)
{for (k = 0, k <2; k + +)
{
court <<"C [" <<j k <<"]["<< <<"]= "<<C [j] [k] <<endl;;
}
}
getch ();
}
court <<endl; / / summing arrays A and B
for (j = 0, j <3; j + +)
{for (k = 0, k <2; k + +)
{
C [j] [k] = A [j] [k] + B [j] [k];
}
} / / display the sum array
for (j = 0, j <3; j + +)
{for (k = 0, k <2; k + +)
{
court <<"C [" <<j k <<"]["<< <<"]= "<<C [j] [k] <<endl;;
}
}
getch ();
}
5. Array Advantage
• Array is suitable for random access. Any element in the array can be referenceddirectly without going through the other elements.
• If you are in a location element, it is very easy to drill down to the neighboringelements, both elements of the predecessor or successor element 3
• If the array elements are the values of independent and all must be maintained, then the use of highly efficient storage
6. Weakness Array
• Arrays must be of type homogeneous. We can not have arrays in which one elementis a character, another element numbers, and other elements are other types
• Most programming languages are difficult to implement a static array is resized at run time. When the addition and reduction occurs continuously, then the staticrepresentation
• Not efficient in memory usage
• menyiakan much computing time
• In an application, the static representation is not possible
• Array is suitable for random access. Any element in the array can be referenceddirectly without going through the other elements.
• If you are in a location element, it is very easy to drill down to the neighboringelements, both elements of the predecessor or successor element 3
• If the array elements are the values of independent and all must be maintained, then the use of highly efficient storage
6. Weakness Array
• Arrays must be of type homogeneous. We can not have arrays in which one elementis a character, another element numbers, and other elements are other types
• Most programming languages are difficult to implement a static array is resized at run time. When the addition and reduction occurs continuously, then the staticrepresentation
• Not efficient in memory usage
• menyiakan much computing time
• In an application, the static representation is not possible
0 comments:
Post a Comment
thank you for visiting my blog and comment here. I hope the commentary contains a comment which intend to build and repair. criticism and suggestions I gladly accept.