Selasa, 20 Februari 2018

1-array&pointer-2101660790-ihsan


Pinter and array
Array adalah kumpulan dari nilai-nilai data bertipe sama dalam urutan tertentu yang menggunakan sebuah nama yang sama.
Nilai-nilai data di suatu larik disebut dengan elemen-elemen larik.
Letak urutan dari suatu elemen larik ditunjukkan oleh suatu subscript atau suatu index.
Menurut dimensinya, array dapat dibedakan menjadi :
1.      Array berdimensi satu
o       Setiap elemen array dapat diakses melalui index
o       Index array secara default dimulai dari 0
•      Declaration:
•      int arr[5];
•      Accessing:
•      arr[0] = 7;
•      arr[1] = 2;
•      arr[2] = 13;
•      arr[3] = 13;
•      arr[4] = 13;
2.      Array berdimensi dua
–          Array dua dimensi merupakan array yang terdiri dari m buah baris dan n buah buah kolom. Bentuknya dapat berupa matriks atau tabel.
•      Declaration:
•      int arr[3][6];
•      Accessing:
•      arr[0][2] = 2;
•      arr[2][1] = 9;
•      arr[1][5] = 13;
•      arr[2][4] = 10;

3.      Array multidimensi
–        Array multidimensi merupakan array yang mempunyai ukuran lebih dari dua. Bentuk pendeklarasian array multidimensi sama saja dengan deklarasi array dimensi satu maupun dimensi dua.
•      Declaration:
•      int arr[4][3][7][10];
•      Accessing:
•      arr[0][2][2][9]= 2;
•      arr[2][1][6][0]= 9;
•      arr[3][0][0][6]= 13;
•      arr[2][1][3][8]= 10;
Operations in Array
There are a number of operations that can be performed
on arrays. They are:
•         Traversal
•         Insertion
•         Searching
•         Deletion
•         Merging
•         Sorting

Pointer

·         Pointer adalah suatu variabel yang menunjuk ke alamat memory variabel yang lainnya.
·         Suatu pointer bukan berisi dengan suatu nilai data seperti halnya pada variabel biasa, variabel pointer berisi dengan suatu alamat.
·         Untuk mendeklarasikan variabel pointer kita menggunakan tanda asterik / bintang (*) didepan variabel yang di deklarasikan pada tipe data tertentu.
Contoh :
int a  = 10;
int *p = &a;
printf( “%d\n”, *p );
a  = 17;
*p = 20;
printf( “%d\n”, a );

DATA Type
•      Data Type is a collection of objects and a set of operations that act on those objects.
•      For example, the data type int consists of:
•         objects             : 0, +1, -1, +2, -2, etc
•         operations        : +, -, *, /, %, etc
•      Example of predefined data types are int, char, float.

Abstract Data Type
•      Abstract Data Type (ADT) is a data type that is organized in such a way that the specification of the objects and the specification of the operations on the objects is separated from the representation of the objects and the implementation of the operations.
•      C/C++ has a concept called class and struct which assist the programmer in implementing abstract data type.
•      Supposed we want to create an ADT of natural number which has integer number as objects and several functions as operation.
•      structure Number is
            objects : an integer x
            functions         :
                        bool is_zero()  if ( x == 0 ) return TRUE else return FALSE
                        bool equal(y)   if ( x == y ) return TRUE else return FALSE
                        void set(y)       x = y
                        void add(y)     x = x + y
                        int get ()                      return x

nama: ihsan 
nim: 2101660790


Tidak ada komentar:

Posting Komentar