A
arnuld
this wroding is directly from "C++ Primer" by Lippman et al, 4/e:
"a parameter can be a pointer, in which case the argument pointer is
copied. as with any non-reference type parameter, changes made to the
parameter are made to the local copy. if function assigns a new value to
the parameter, the callingpointer value is unchanged"
/* C++ Primer - 4/e
*
* section 7.2.1
*
* pointers as parameters/arguments to functions *
*/
#include <iostream>
void reset_val(int* px)
{
*px = 0;
}
int main()
{
int i = 3;
int* ip = &i;
std::cout << "i = " << i << ",\t"
<< "*ip = " << *ip << "\n\n";
reset_val(ip);
std::cout << "i = " << i << ",\t"
<< "*ip = " << *ip << '\n';
return 0;
}
======== OUTPUT ==========
$ g++ -ansi -pedantic -Wall -Wextra 7.2.1.cpp $ ./a.out
i = 3, *ip = 3
i = 0, *ip = 0
look the original-value of "i" is changed. what exactly the author is
trying to say ?
"a parameter can be a pointer, in which case the argument pointer is
copied. as with any non-reference type parameter, changes made to the
parameter are made to the local copy. if function assigns a new value to
the parameter, the callingpointer value is unchanged"
/* C++ Primer - 4/e
*
* section 7.2.1
*
* pointers as parameters/arguments to functions *
*/
#include <iostream>
void reset_val(int* px)
{
*px = 0;
}
int main()
{
int i = 3;
int* ip = &i;
std::cout << "i = " << i << ",\t"
<< "*ip = " << *ip << "\n\n";
reset_val(ip);
std::cout << "i = " << i << ",\t"
<< "*ip = " << *ip << '\n';
return 0;
}
======== OUTPUT ==========
$ g++ -ansi -pedantic -Wall -Wextra 7.2.1.cpp $ ./a.out
i = 3, *ip = 3
i = 0, *ip = 0
look the original-value of "i" is changed. what exactly the author is
trying to say ?