LectureTwentyone

# LectureTwentyone - Lecture 21 Pointers – Part III By...

This preview shows pages 1–5. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lecture 21 Pointers – Part III By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department The Hashemite University ٢ Arrays of Pointers ¡ Arrays can contain pointers ¡ Commonly used to store an array of strings char *suit[ 4 ] = {"Hearts", "Diamonds", "Clubs", "Spades" }; ¡ Each element of suit is a pointer to a char * (a string) ¡ The strings are not in the array, only pointers to the strings are in the array ¡ suit array has a fixed size, but strings can be of any size suit[3] suit[2] suit[1] suit[0] ’H’ ’e’ ’a’ ’r’ ’t’ ’s’ ’\0’ ’D’ ’i’ ’a’ ’m’ ’o’ ’n’ ’d’ ’s’ ’\0’ ’C’ ’l’ ’u’ ’b’ ’s’ ’\0’ ’S’ ’p’ ’a’ ’d’ ’e’ ’s’ ’\0’ The Hashemite University ٣ Function Pointers I ¡ Pointers to functions ¡ Contain the address of the function ¡ Similar to how an array name is the address of its first element ¡ Function name is starting address of code that defines function ¡ Function pointers can be ¡ Passed to functions ¡ Stored in arrays ¡ Assigned to other function pointers The Hashemite University ٤ Function Pointers II ¡ Example: bubblesort ¡ Function bubble takes a function pointer ¡ The function determines whether the the array is sorted into ascending or descending sorting ¡ The argument in bubble for the function pointer bool ( *compare )( int, int )...
View Full Document

{[ snackBarMessage ]}

### Page1 / 12

LectureTwentyone - Lecture 21 Pointers – Part III By...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online