Materi
Array Struktur Alokasi Memori
Arna Fariza
Array
Sekumpulan variabel yang mempunyai tipe yang sama Bersifat statis Alokasi memori dilakukan saat deklarasi Contoh :
int nilai[10]; char nama[20]; float pecahan[6];
Arna Fariza
Pointer
Variabel yang menunjuk ke lokasi alamat tertentu Bersifat Dinamis Contoh :
void main() { int a, int *b; a=5; b=&a; printf(%d %d, a, *b); } char *nama;
Struktur
Sekumpulan variabel yang mempunyai tipe yang berbeda Contoh :
struct tanggal { int tgl; char bulan[15]; int tahun; };
Arna Fariza
Struktur
typedef struct tanggal TGL; struct tanggal { int tgl; char bulan[15]; int tahun; }; typedef struct tanggal { int tgl; char bulan[15]; int tahun; } TGL;
Arna Fariza
Array of Structure
typedef struct tanggal { int tgl; char bulan[15]; int tahun; } TGL; TGL tgl_lahir[30];
Arna Fariza
Pointer to Structure
typedef struct tanggal { int tgl; char bulan[15]; int tahun; } TGL; TGL *tgl_lahir;
Arna Fariza
Alokasi Memori
Mengalokasikan memori untuk variabel pointer char *nama; nama=(char *) malloc (sizeof(char)); nama=(char *) malloc (20*sizeof(char)); char *nama[10]; nama[0]=(char *) malloc (20*sizeof(char)); nama[9]=(char *) malloc (20*sizeof(char));
Arna Fariza
Alokasi Memori
TGL *tgl_lahir; tgl_lahir=(TGL *) malloc (sizeof(TGL)); tgl_lahir=(TGL *) malloc (20*sizeof(TGL); TGL *tgl_lahirA[10]; tgl_lahirA[0]=(TGL *) malloc (2*sizeof(TGL)); tgl_lahirA[9]=(TGL *) malloc (2*sizeof(TGL));
Arna Fariza
10