【发布时间】:2021-08-17 14:04:08
【问题描述】:
我试图通过取消引用指针来访问动态创建的数组,但它显示错误。
#include <bits/stdc++.h>
using namespace std;
int main (){
int *arr = new int[10];
arr[0]=10;
int *num = new int(10);
cout << *num << " "<<num[10]<<endl;
cout << arr[0];
}
据我所知,如果您想为指针对象分配一些值,我们必须取消引用它,然后像*num =10 一样应用,但就数组而言,我无法执行类似*(arr[0])=10 的操作
它显示像operand of '*' must be a pointer but has type "int"这样的错误
谁能给我解释一下?
【问题讨论】:
-
请不要将问题改成其他问题,而是创建一个新问题。
-
G. Sliepen 我无法提出新的问题,所以我正在编辑现有的问题。