我试图围绕指针,引用和地址包裹我的头,但每次我想我都会有意想不到的东西弹出来。指针和结构
为什么我们不需要在此示例中取消引用结构来设置值?
// pointer_tet.cpp
#include <iostream>
struct example
{
char name[20];
int number;
};
int main()
{
using namespace std;
example anExample = {"Test", 5};
example * pt = &anExample;
pt->number = 6;
cout << pt->number << endl;
int anotherExample = 5;
int * pd = &anotherExample;
*pd = 6;
cout << *pd << endl;
return 0;
}
谢谢!
编辑:谢谢你的回答!我困惑的是无法设置* pt.number = 6.
我没有看到任何你不取消设置值的地方。 – 2013-03-13 20:05:03
嗯,你**是取消引用'pt'。 – AndiDog 2013-03-13 20:05:20
你认为你不去参考? – tletnes 2013-03-13 20:06:08