阅读背景:

访问struct字段的特定数组元素时,C程序崩溃

来源:互联网 

I have this code:

我有这个代码:

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

struct game_s {
  bool isOccupied[20][10];
};

int main() {
  struct game_s* game_p;
  game_p->isOccupied[0][8] = false;
  printf("0,8 works\n");
  game_p->isOccupied[2][8] = false;
  printf("2,8 works\n");
  game_p->isOccupied[1][7] = false;
  printf("1,7 works\n");
  game_p->isOccupied[1][9] = false;
  printf("1,9 works\n");
  game_p->isOccupied[1][8] = false; // crashes the program
  printf("1,8??");
}
#include <stdio.h



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: