& x |
evaluates (returns) the address of the variable x
Example:
int main( int argc, char *argv[] ) { int x; f( &x ); // Pass the address of the int variable x as parameter ... } |
void f ( int * a ) { // a can store an address of an int variable ... // The way to use the variable a is: *a } |
void f( int *a ) // No special & symbol... { *a = *a + 1; } int main(int argc, char *argv[]) { int x = 10; f( &x ); // Pass address of x cout << x; // ****** Prints 11 !!! } |
In other words: a points to the variable x of main()
*a returns x !!! |
*a = *a + 1 will update x in main() !!! |