문제

What is the difference between following two function definitions?

Function declaration:

void fun(int* p);

Function Definition 1:

             void fun (int* p){
                       p += 1;
                      }

Function Definition 1:

                 void fun (*p){
                       p += 1;
                          }
도움이 되었습니까?

해결책 2

Passing an int by pointer:

void fun (int* p) ;

void fun (int* p)
{
    *p += 1 ; // Add 1 to the value pointed by p.
}

Passing an int by reference:

void fun (int& p) ;

void fun (int& p)
{
    p += 1 ; // Add 1 to p.
}

다른 팁

There's only one valid function definition, the 1st one you gave:

Function Definition 1:

 void fun (int* p) {
    p += 1;
 }

Also you probably meant:

    (*p) += 1;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top