0

我在理解如何从 C++ 中的多维数组中获取元素时遇到问题。代码在我的粒子光子上运行,看起来我没有任何编译错误,但是当我检查我的打印值时,我期望得到 1000 的返回值。相反,我得到的似乎是一致的随机值 -1069809521。我知道问题区域是TotalTime += (*FaceEmoteTimeArray[FaceNumber][i]);,但不确定为什么。完整代码:

const int FaceEmoteTime0[31] = {143, 143, 143, 142, 143, 143, 143};
const int FaceSize0 = sizeof(FaceEmoteTime0) / sizeof(FaceEmoteTime0[0]);

const int* FaceEmoteTimeArray [][FaceSize0] = {FaceEmoteTime0};
const int FaceSizeArray[] = {FaceSize0};

int TotalTime;
int Plays;
int FaceNumber = 0;

void setup() {
  Serial.begin(115200);
}

void loop() {
  if (Plays == 0) {
    for (int i = 0; i < (FaceSizeArray[FaceNumber]); i++) {
      TotalTime += (*FaceEmoteTimeArray[FaceNumber][i]);
    }
    Serial.println(TotalTime);
    Plays++;
  }
}
4

0 回答 0