Frage

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;
                          }
War es hilfreich?

Lösung 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.
}

Andere Tipps

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;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top