• Tidak ada hasil yang ditemukan

Fundamentals of Programming

N/A
N/A
Protected

Academic year: 2024

Membagikan "Fundamentals of Programming"

Copied!
20
0
0

Teks penuh

(1)

Fundamentals of Programming

session 25

Array of pointers

(2)

Array of pointers

int *a[10];

char *s[20];

(3)

Array of pointers

arrayofpointers0.c

(4)

Array of pointers

arrayofpointers1.c

(5)

Array of pointers

arrayofpointers1.c

seasons[3]

seasons[2]

seasons[1]

seasons[0] 'S' 'p' 'r' 'i' 'n' 'g' 0

'S' 'p' 'r' 'i' 'n' 'g' 0 'F' 'a' 'l' 'l' 0

'S' 'p' 'r' 'i' 'n' 'g' 0

(6)

Array of pointers

arrayofpointers2.c

seasons[3]

seasons[2]

seasons[1]

seasons[0] 'S' 'p' 'r' 'i' 'n' 'g' 0

'S' 'p' 'r' 'i' 'n' 'g' 0 'F' 'a' 'l' 'l' 0

'S' 'p' 'r' 'i' 'n' 'g' 0

(7)

Array of pointers

arrayofpointers3.c

(8)

Array of pointers

arrayofpointers3.c

(9)

Referencing pointers of arrays

seasons[1][3] = ?

seasons[3]

seasons[2]

seasons[1]

seasons[0] 'S' 'p' 'r' 'i' 'n' 'g' 0

'S' 'p' 'r' 'i' 'n' 'g' 0 'F' 'a' 'l' 'l' 0

'S' 'p' 'r' 'i' 'n' 'g' 0

(10)

Referencing pointers of arrays

seasons[1][3]

= (seasons[1]) [3]

seasons[3]

seasons[2]

seasons[1]

seasons[0] 'S' 'p' 'r' 'i' 'n' 'g' 0

'S' 'p' 'r' 'i' 'n' 'g' 0 'F' 'a' 'l' 'l' 0

'S' 'p' 'r' 'i' 'n' 'g' 0

(11)

Referencing pointers of arrays

seasons[1][3]

= (seasons[1]) [3] = 'i'

seasons[3]

seasons[2]

seasons[1]

seasons[0] 'S' 'p' 'r' 'i' 'n' 'g' 0

'S' 'p' 'r' 'i' 'n' 'g' 0 'F' 'a' 'l' 'l' 0

'S' 'p' 'r' 'i' 'n' 'g' 0

(12)

Array of pointers

arrayofpointers4.c

(13)

Array of pointers

arrayofpointers4.c

(14)

Array of pointers vs. 2D arrays

3 2 1 0 Memory

13 12 11 10

23 22 21 20

3 2 1 0

13 12 11 10

23 22 21 20 a[2]

a[1]

a[0]

(15)

Array of pointers vs. 2D arrays

3 2 1 0 Memory

13 12 11 10

23 22 21 20

3 2 1 0

13 12 11 10

23 22 21 20 a[2]

a[1]

a[0]

(16)

● Advantages of array of pointers

○ Rows of different length (more flexibility, saving memory)

Array of pointers vs. 2D arrays

names[3]

names[2]

names[1]

names[0] 'A' 'k' 'b' 'a' 'r' 'i' 0

'A' 'l' 'a' 'v' 'o' 0 'N' 'a' 'r' 'i' 0

'B' 'i' 'a' 'k' 'i' 'A' 's' 'l' 'e' 'T' 'e' 'h' 'r' 'a 'n' 'i' 0

(17)

● Advantages of array of pointers

○ Rows of different length (more flexibility, saving memory)

Array of pointers vs. 2D arrays

(18)

Array of pointers vs. 2D arrays

3 2 1 0 Memory

13 12 11 10

23 22 21 20

3 2 1 0

13 12 11 10

22 21 20 14 a[2]

a[1]

a[0]

(19)

● Advantages of array of pointers

○ Rows of different length (more flexibility, saving memory)

○ Swapping two rows efficiently

Array of pointers vs. 2D arrays

names[3]

names[2]

names[1]

names[0] 'A' 'k' 'b' 'a' 'r' 'i' 0

'A' 'l' 'a' 'v' 'o' 0 'N' 'a' 'r' 'i' 0

'B' 'i' 'a' 'k' 'i' 'A' 's' 'l' 'e' 'T' 'e' 'h' 'r' 'a 'n' 'i' 0

(20)

● Advantages of 2D arrays

○ Efficiency (in accessing elements)

Array of pointers vs. 2D arrays

Referensi

Dokumen terkait

The Fundamentals of Java Programming Language course provides a conceptual understanding of Object Oriented programming.. The course also teaches students how to use the JAVA 

Superior root mean square error RMSE is obtained using the new KR-AVS array approach compared to the other geometries of the non-uniform linear array, the 2D L-shape array, and the 2D

STL: Iterators cont’d Iterators and their Characteristics cont’d 38 Iterator Access method Direction of movement I/O capability Input Linear Forward only Read-only Output Linear

Three basic control structures Sequence • Straight forward execution of one processing step after another • Each instruction will be executed in the order in which it appears

Reduces waste in all procedures: -eliminates unnecessary inventories -energy saving -efficiency of area usage -reduces cost Advantages of green 5S implementation in

ALGORITHM OF BUBBLE SORT Bubble sort algorithm starts by comparison of the first two elements of an array and swapping if required, i.e., if you want to sort the elements of an array

Table 2: Advantages and challenges of the gig economy perceived by the hospitality undergraduate students from Malaysian public universities Advantages Challenges Flexibility ●

Advantages of surface mining It is generally conceded that surface mining is more advantageous than underground mining in terms of recovery, grade control, economy, flexibility of