c++ - 指针算术和取消引用

标签 c++

在下面的代码中,任何人都可以向我解释一下粗体行是做什么的。

struct southParkRec {
    int stan[4];
    int *kyle[4];
    int **kenny;
    string cartman;
};

int main()
{
    southParkRec cartoon;
    cartoon.stan[1] = 4;
    cartoon.kyle[0] = cartoon.stan + 1;
    cartoon.kenny = &cartoon.kyle[2];
    *(cartoon.kenny + 1) = cartoon.stan;  //What does this line do?

    return 0;
}

最佳答案

把它想象成

cartoon.kenny[1] = cartoon.stan;

它们本质上是一样的

关于c++ - 指针算术和取消引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3105062/

相关文章:

c++ - 在 C++ 中构造数组元素在循环中调用 new 而不是 new[] 是否合法?

c++ - 为什么这个 C++ 代码不能编译?

c++ - 从模板函数内部的类型中删除 const-ness

c++ - 将 Libjson 7.6.1 转换为 Visual Studio 2012 时出错

c++ - RAII理解——有界指针的访问方法

c++ - 排序子网格/VBO

c++ - 为什么我必须在覆盖 [C++] 时重新声明一个虚函数

c++ - 在 C++ 中强制最后破坏某些东西

c++ - C和C++的区别

c++ - 线程: Termination of infinite loop thread in c++