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.
}
質問
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;