运算符和指针运算符的地址

address of operator and pointer operator

本文关键字:运算符 地址 指针      更新时间:2023-10-16

以下两个函数定义有什么区别?

函数声明:

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.
}