Initialization of pointer arrays

Nasza ocena:

3
Wyświetleń: 546
Komentarze: 0
Notatek.pl

Pobierz ten dokument za darmo

Podgląd dokumentu
Initialization of pointer arrays - strona 1 Initialization of pointer arrays - strona 2

Fragment notatki:

Initialization of pointer arrays • Problem: write a function month_name(n) , returning the name of the n -th month (in the form of a pointer to a string) • We will use a static array • month_name contains an array of pointers to 13 strings • … returns a pointer to one of them • How to initialize that array • Call: printf(”The 5th month is: %s\n”, month_name(5)); /* month_name: return name of n-th month */ /* acc. to K&R */ char *month_name(int n) { static char *name[] = { "Illegal month", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; return (n 12) ? name[0] : name[n]; } ... zobacz całą notatkę



Komentarze użytkowników (0)

Zaloguj się, aby dodać komentarz