小编lif*_*sis的帖子

我在C中的(char*)元素数组上有三个循环.为什么第三个失败?

在尝试使用C语言中的字符串数组步进的方法时,我开发了以下小程序:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


typedef char* string;

int main() {
  char *family1[4] = {"father", "mother", "son", NULL};
  string family2[4] = {"father", "mother", "son", NULL};

  /* Loop #1: Using a simple pointer to step through "family1". */
  for (char **p = family1; *p != NULL; p++) {
    printf("%s\n", *p);
  }
  putchar('\n');

  /* Loop #2: Using the typedef for clarity and stepping through
   * family2. */
  for (string *s = family2; *s != NULL; s++) {
    printf("%s\n", *s);
  } …
Run Code Online (Sandbox Code Playgroud)

c arrays pointers memory-address

15
推荐指数
2
解决办法
1304
查看次数

标签 统计

arrays ×1

c ×1

memory-address ×1

pointers ×1