gpt4 book ai didi

c++ - 类型 'int*' 和 'int*' 到二进制 'operator+' 的无效操作数

转载 作者:搜寻专家 更新时间:2023-10-31 02:01:42 24 4
gpt4 key购买 nike

<分区>

我正在试验一些基本的 C++ 示例。我无法理解上述编译错误的原因。这是我正在尝试的示例。

void update(int *a,int *b) {   
int c = a+b; // Error occurs here
int d = a-b; // But not here
int e = a*b; // Error
int f = a/b; // Error
}

int main(){
int a = 4, b = 8;
update(&a, &b);
}

我理解上面的 a-b 案例给出了两个内存地址之间的差异作为 int 大小的倍数,所以 d将为 -1(更新:假设 ab 是内存中的连续变量)。

谁能解释一下其他三种情况下发生了什么以及错误的含义。

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