gpt4 book ai didi

C++ 指针语法不正确?

转载 作者:太空宇宙 更新时间:2023-11-04 14:47:52 24 4
gpt4 key购买 nike

<分区>

我在这个链接中看到了这段代码- http://www.tutorialspoint.com/cplusplus/cpp_pointers_vs_arrays.htm .看第一段代码。

#include <iostream>

using namespace std;
const int MAX = 3;

int main ()
{
int var[MAX] = {10, 100, 200};
int *ptr;

// let us have array address in pointer.
ptr = var;
for (int i = 0; i < MAX; i++)
{
cout << "Address of var[" << i << "] = ";
cout << ptr << endl;

cout << "Value of var[" << i << "] = ";
cout << *ptr << endl;

// point to the next location
ptr++;
}
return 0;
}

不应该是 ptr = &var 而不是 ptr = var 吗?它在评论下方。为什么它简单地声明为 var 而不是 &var

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com