运算符和指针运算符的地址
address of operator and pointer operator
以下两个函数定义有什么区别?
函数声明:
void fun(int* p);
函数定义 1:
void fun (int* p){
p += 1;
}
函数定义 1:
void fun (*p){
p += 1;
}
只有一个有效的函数定义,你给出的第一个:
函数定义 1:
void fun (int* p) {
p += 1;
}
你也可能意味着:
(*p) += 1;
通过指针传递int
:
void fun (int* p) ;
void fun (int* p)
{
*p += 1 ; // Add 1 to the value pointed by p.
}
通过引用传递int
:
void fun (int& p) ;
void fun (int& p)
{
p += 1 ; // Add 1 to p.
}
相关文章:
- 重载运算符有地址吗?
- 重载 ostream << 运算符,指针作为参数,导致输出上的内存地址
- 变量地址的运算符[]是如何工作的
- 在分配指向数组内存地址的指针时,为什么不必使用地址运算符?
- 后缀 "&" (地址) 运算符 在 C++ 中
- C++ - <<运算符重载,链表 - 地址而不是标准输出
- 使用指针,打印地址而不是值,为什么?(使用运算符)
- 间接寻址运算符如何返回带有运算符重载的指针地址
- 重载运算符地址的用例
- 不太明白 & 运算符的地址在这个结构中做什么,以及它如何能够访问其他成员变量
- 赋值不起作用,但带有取消引用运算符的地址起作用?
- 地址运算符是否返回变量引用的对象的地址
- 为什么在递增后使用 [] 运算符访问指针数组会返回错误地址的当前内存位置
- C++ *和运算符的取消引用地址?
- 获取运算符的地址<<在 gcc 4.8 中失败
- 是否有标准的C++函数,类似于地址运算符&?
- 为什么通过运算符的地址获得的指针不是lvalue
- 为什么 std::swap 不适用于地址运算符
- 运算符和指针运算符的地址
- 在执行函数指针时,使用运算符地址与不使用运算符地址的目的是什么