This chapter illustrates each of these scenarios, along with the coordination and data shming strategies that underlie their effective implementation. To provide a focus for this discussion, our examples favor Java as the language of illustration. Concurrency features in several other languages are summalized at the end of the chapter. | CSC103: Introduction to Computer and Programming Lecture No 23 Previous lecture Standard library string functions strlen() strcpy() strcat() strcmp() Today’s lecture outline Exercise program Two dimensional array of characters Array of pointer to string Garbage value Dynamic memory allocation Free function Exercise program Write the definition of following function then call it from main to check it works or not int countchar(char *str, char ch); write to program Two-Dimensional Array of Characters It is same as 2-D array of integer except that each 1-D array in 2-D array terminates at NULL character int a[3][6] 2 6 8 9 2 -9 5 4 7 8 8 0 4 2 2 0 1 0 char b[3][6] h e l l o \0 w o r l d \0 h a r r y \0 Initializing 2 D array of character a h m a d \0 f a h a d \0 n a z i a \0 w a q a s \0 a l i \0 s a l m a n \0 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 row column Cont. a h m a d \0 a l i \0 n a z i a \0 0 1 2 3 4 5 6 7 8 9 0 1 2 &name[i][0] a h m a d \0 a l i \0 n a z i a \0 Wastage of memory Example program Example program asks you to type your name. When you do so, it checks your name against a master list to see if the name is present in the list or not Go to program Array of pointers to string A pointer variable always contains an address An array of pointers would contain a number of addresses Array contains base addresses of respective names Base address of “ahmad” is store in names[0] Memory map 0 1 2 3 4 5 a h m a d \0 600 f a h a d \0 668 w a q a s \0 745 n a z i a \0 712 a l i \0 789 s a l m a n \0 800 600 668 712 745 789 800 Cont. Another reason to use an array of pointers to store strings is to obtain greater ease in manipulation of the strings Let see two programs first uses a 2-D array of characters to store the names, whereas the second uses an array of pointers to strings. The purpose of both the programs is very simple. We want to exchange the position of the names “waqas” and “ali”. Program using array of character Logic for exchanging 4th and 5th name Go to | CSC103: Introduction to Computer and Programming Lecture No 23 Previous lecture Standard library string functions strlen() strcpy() strcat() strcmp() Today’s lecture outline Exercise program Two dimensional array of characters Array of pointer to string Garbage value Dynamic memory allocation Free function Exercise program Write the definition of following function then call it from main to check it works or not int countchar(char *str, char ch); write to program Two-Dimensional Array of Characters It is same as 2-D array of integer except that each 1-D array in 2-D array terminates at NULL character int a[3][6] 2 6 8 9 2 -9 5 4 7 8 8 0 4 2 2 0 1 0 char b[3][6] h e l l o \0 w o r l d \0 h a r r y \0 Initializing 2 D array of character a h m a d \0 f a h a d \0 n a z i a \0 w a q a s \0 a l i \0 s a l m a n \0 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 row column Cont. a h m a d \0 a l i \0 n a z i a \0 0 1 2 3 4 5 6 7 8 9 0 1 2 &name[i][0] a h m a d \0 a l i \0 n a z i a \0 Wastage of memory .