以下は、名前の一覧の中から1つずつ指定して、あいさつを表示するプログラムです。ただし、コメントの部分に入れるべきコードが隠れています。

どんなコードが入るか分かりますか?
main.c
#include <stdio.h>
#include <stdlib.h>
void GreetTo(int nameIndex, const char **ppNames) {
printf("Hello, %s!\n", ppNames[nameIndex]);
}
int main(void) {
/* ここに入るコードは? */ = {
"Leo",
"Yuki"
};
GreetTo(0, names);
GreetTo(1, names);
return EXIT_SUCCESS;
}
実行結果
Hello, Leo!
Hello, Yuki!

おお〜、穴埋め問題ですね!

たまにはこういうのもいいでしょ?

はい。ちょっと楽しそうです!

えっと、これがあいさつを表示する関数かな。……ん?
void GreetTo(int nameIndex, const char **ppNames) {
printf("Hello, %s!\n", ppNames[nameIndex]);
}

あのー、
**
っていうのは、タイプミスか何かですかね?

ああ、それはポインタのポインタよ。

うわぁ、何ですかそれ?

うーん、ちょっと難しかったかな。

はい、あんまりイメージがわかないです。

それじゃあ、似ているけどもう少し簡単なプログラムで練習しましょ。
main.c
#include <stdio.h>
#include <stdlib.h>
void PrintNumber(int numberIndex, int *pNumbers) {
printf("Number = %d\n", pNumbers[numberIndex]);
}
int main(void) {
int numbers[] = {
123,
456
};
PrintNumber(0, numbers);
PrintNumber(1, numbers);
return EXIT_SUCCESS;
}
実行結果
Number = 123
Number = 456

あ、これなら分かりそうですよ!

整数の配列があって……
int numbers[] = {
123,
456
};

この関数にインデックスと配列を渡して、要素を1つ表示してる!
void PrintNumber(int numberIndex, int *pNumbers) {
printf("Number = %d\n", pNumbers[numberIndex]);
}

ここまでは大丈夫そうね。それじゃあ、問題のプログラムに戻ってみてね。

はーい!

「名前の一覧」を表すにはどんな型が必要か考えてみましょう。