Message from C, C++ talks

June 2019

— And

— Now, if you want to show your mother the flower pot, you have two options

— Either you carry the flower pot to her

— Or you tell her the flower pot number

— 

A pointer is not complex, in the end it's an integral value (a number) such as an integer.
Using pointers let's you access the same object in multiple places. E.g. you can access the local i in main although you are in a different function foo

void foo(int * pi) {
*pi = 7;
}

int main() {
int i = 3;
printf("%d", i);
foo(&i);
printf("%d", i);
}

— The flower pot number, in this case, is a pointer

— That's only the purpose of pointers

— Imagine, every named object (a variable, such as int i) has a unique ID, it's address. A pointer stores this id. By using a pointer you can access the same object from basically everywhere.

Message permanent page

— What did you expect?

— Foo(&I);

— Explain this

— That

— Pi is had a variable

— 7

— Would it be achievable with static too ?