example 1:
int a = 5;
int *b = &a;
note: get the memory address of a, and store it in an int point b. &b == a == 5.
example 2:
void swap(int *x, int *y){ // normal pointer usage.
int temp = *x;
*x = *y;
*y = temp;
}
void swap(int &x, int &y){ // quote here means use a different name and same memory.
int temp = x;
x = y;
y = temp;
}
No comments:
Post a Comment