實習講師 Jason
int a = 3;
int *b = &a;
cout << b << endl; // b = &a = the address of a
cout << *b << endl; // *b = *(&a) = a = the value of a
for(int i = 0; i < 100; i++){
b = new int; // allocate new memory with type int to b
*b = i; // change value of memory that b points to
delete b; // free the memory that b points to
}
struct node {
int val;
node *next;
};
node *a = new node; // allocate new memory with type node
a->val = 1; // a->val = (*a.val) = the value of val in memory that a points to
a->next = new node;
a->next->val = 2; // a->next->val = (a->next)->val
a->next->next = nullptr;
Basically the same thing.