22 lines
596 B
C
22 lines
596 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h> // memset
|
|
|
|
int main()
|
|
{
|
|
char(*names)[32] = (char(*)[32])calloc(3, 32 * sizeof(char)); // 说明: 4 * 32 = 128
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
printf("第 %d 个人的名字: ", i + 1);
|
|
// names + i -> char(*)[32] 二维数组的首地址
|
|
// *(names + i) -> char[32] 一维数组的首地址 (*降维)
|
|
scanf("%s", *(names + i)); // *(names + i) == names[i]
|
|
}
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
printf("%s\n", *(names + i)); // *(names + i) == names[i]
|
|
|
|
free(names);
|
|
|
|
return 0;
|
|
} |