8. Initialization of Pointer Arrays
 
Consider the problem of writing a function month_name(n), which returns a pointer to a character    string containing the name of the n-th month. This is an ideal application for an internal static array.
 
/* month_name: return name of n-th month */
char *month_name(int n)
{
    static char *name[] {
        “Illegal month”,
        “January”, “February”, “March”,
        “April, “May”, “June”,
        “July”, “August”, “September”,
        “October”, “November”, “December”
    };
    return (n < 1 || n > 12) ? name[0] : name[n];
}
 
 
 
 
이전페이지 / 9 / 다음페이지