#include #include #include #define MAX_WORDS 5 void init(char **foo); void print(char *name, char **foo); void printMatrix(char **arr); /* causes compiler warning! */ int main(int argc, char *argv[]) { char *wordArray[MAX_WORDS]; /* compile-time array of char* */ char **wordArray2; /* pointer to char* */ char matrix[MAX_WORDS][30]; wordArray2 = (char**)malloc(MAX_WORDS * sizeof(char*)); /* wordArray2 is now a MAX_WORDS-size array of char*'s */ /* is there any difference between wordArray and wordArray2? */ strcpy(matrix[0],"Jane"); strcpy(matrix[1],"Peter"); wordArray[0] = "Professor"; wordArray[1] = "Nael"; wordArray2[0] = wordArray[1]; wordArray2[1] = wordArray[0]; printMatrix(wordArray); print("wordArray", wordArray); print("wordArray2", wordArray2); printMatrix(matrix); return 0; } void init(char **foo) { int i; for (i = 0; i < MAX_WORDS; i++) foo[i] = NULL; } void print(char *name, char **foo) { int i; printf("printing %s\n", name); for (i = 0; i < MAX_WORDS; i++) printf("%2d %s\n", i, foo[i]); printf("\n"); } void printMatrix(char **arr) /* causes compiler warning! */ /* what's wrong with the parameter type??? */ { int i; for (i = 0; i < MAX_WORDS; i++) printf("%d\t%s\n", i, arr[i]); printf("\n"); }