一个C++程序问题

    int ia[3][4];

    for (auto p = ia; p != ia + 3; ++p) {
// q points to the first element of an array of four ints; that is, q points to an
        for (auto q = *p; q != *p + 4; ++q)
            cout << *q << ' ';
        cout << endl;
    }

这是我照着primer c++ 5th multidimensional array 写的,但是输出的结果中却包含一个'1'
结果:

0 1 0 0 
0 0 0 0 
0 0 0 0 

不太明白这里为什么会有一个'1'呢?

阅读 1.1k
1 个回答

ia 沒有初始化,什麽值都有可能。建議改爲 int ia[3][4] = {0};

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题