You are on page 1of 16

2 DIMENSIONAL

ARRAY, POINTER,
LINKED LIST
By Michael
• An array of arrays is known as 2D array;

• The two dimensional (2D) array in C programming is also


known as matrix. 

2D ARRAY IN C PROGRAMMING
SIMPLE 2D ARRAY EXAMPLE
OUTPUT OF
PROGRAM
There are two ways to initialize a two Dimensional arrays
during declaration.

or

INITIALIZATION OF 2D ARRAY
INITIALIZING A 2D ARRAY
• We can calculate how many elements a two dimensional array can have by using
this formula:
The array arr[n1][n2] can have n1*n2 elements. The array that we have in the
example next is having the dimensions 5 and 4. These dimensions are known as
subscripts. So this array has first subscript value as 5 and second subscript value
as 4.
So the array abc[5][4] can have 5*4 = 20 elements.

• To store the elements entered by user we are using two for loops, one of them is a
nested loop. The outer loop runs from 0 to the (first subscript -1) and the inner for
loops runs from 0 to the (second subscript -1). This way the the order in which user
enters the elements would be abc[0][0], abc[0][1], abc[0][2]…so on. 

STORE USER INPUT DATA INTO 2D


ARRAY
Second Subscript

First Subscript
STORE USER INPUT DATA INTO 2D
ARRAY
Memory locations for the array elements

ACTUAL REPRESENTATION OF THIS


ARRAY IN MEMORY
Data Structures that containing a pointer or pointer to it self

Data Pointer

A single Linked list

Nil/null

LINKED LIST
Data Structures that containing a pointer or pointer to it self

Jane 19 Smith 19 Fulan 19

IT 175 IT 180 IT 183

Fulan 19

IT 183

LINKED LIST
Typedef struct
Struct node
{
type_data Isi;
simpul -> next;
}

LINKED LIST
Array: if there is a new data, we have to find the correct position and make a room
for it. So there will be a data movement (move data bit down).
Linked List: If there is a new data, we just need to move the pointer to the new data,
and so on.

Push = insert
Pop = delete
Top = take/hide

LIFO

LINKED LIST
Penunjuk alamat pada memori computer yang menyimpan data

Null

POINTER
Contoh pointer pada Record

Type Pkaryawan = ^Tkaryawan;


Tkaryawan = record
Nama : string [30];
Posisi : char;
Gaji : longint;
end;

Var p:^Tkaryawan;

Begin
Clrscr; Tintin K 1000000
New(p) ;
P^.nama :=‘Tintin’;
P^.posisi :=‘K’
P^.gaji := 10000000
Writeln (p^.nama,’ ‘,p^.posisi,’ ‘ ,p^.gaji);
readln

POINTER
#include<iostream>
#include <string.h>
using namespace std;
struct Student{ string name;
string ID;
float GPA;
int smstr;
Student *next; };

Temp -> next = cur;


If (prev)
prev -> next = temp;
Else
head = temp;

POINTER

You might also like