Lauri
Explain me this point with examples
Lauri
Give me written example
BinaryByter
Sorry, but i'm too lazy ¯\_(ツ)_/¯
Dima
void* ptr = (void* )object; // polymorphism in c
BinaryByter
Dima
Yup
BinaryByter
polymorphism is a bit of a stretch here 😅
Lauri
BinaryByter
if it was, however, it would get the pointer of object
BinaryByter
and store it in ptr
Dima
Pointer points to an address of object in memory, in some cases that you don’t have to copy it or whatever
Lauri
Copy wt
Dima
Guess it
BinaryByter
Copy wt
the value of the variable
BinaryByter
string a = "!kölaksdjfölaksdjf öasdkjf öklJ"
string b = a;
BinaryByter
string a will be completely copied into string b
Dima
BinaryByter
if you do
string* b = &a; (the pointer b points to string a)
you don'T copy whats IN the string but WHERE to find the content of the string
Lauri
Like copying a string with copy paste is very hard
BinaryByter
Yea
BinaryByter
instead, you just remember where the string is
BinaryByter
so you just copy the ADRESS of the string
klimi
But if you need to modify it ¯\_ (ツ) _/¯
Lauri
Can't do Ctrl + f ?
BinaryByter
BinaryByter
one is code, the other is what hte user does
Lauri
It's very hard to understand pointers
Lauri
I don't know any programmer url to tutor me
klimi
Lauri
Irl
klimi
Even my teacher is more stupid than me
Lauri
Yeah sure teachers are very dumb
BinaryByter
Think of them as "positions in memory"
Lauri
Dima
do you even “please”?
Dima
Lauri
The purpose of group is helping so that's not a favor
Dima
It’s not the purpose
Lauri
Ok sry
BinaryByter
Dima
the group purpose is to discuss stuff in a good manner
BinaryByter
imagine the RAM as a strip of many little empty flower pots
BinaryByter
every flower pot has a number on it
Lauri
And
BinaryByter
Now, if you want to show your mother the flower pot, you have two options
BinaryByter
either you carry the flower pot to her
BinaryByter
or you tell her the flower pot number
olli
It's very hard to understand pointers
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);
}
Lauri
That's only the purpose of pointers
olli
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.
olli
Lauri
Lauri
Explain this
Lauri
That
Lauri
Pi is had a variable
Lauri
7
Badugar
Badugar
When you'd try to access i from main in foo()
Badugar
Also .. what's a practical use of triple pointers ? 🤔
Pavel
Badugar
Dima
fuc*** hell.
Pavel
Yes.
Never seen such a thing in real code
Badugar
Pavel
Maximum two, when someone wants to pass a pointer to a C-array. To allocate it in the function and return the pointer via parameter
Pavel
But three asterisks sound a little bit insane. Can't imagine why someone would do that
Pavel
Well, two already too bad in my opinion
Pavel
But I guess its how things being done in pure C (glad that I'm not doing pure C)
Mihail
Pavel
Well vector<vector<vector<...>>>> doesn't sound much better, but at least it's safe :)
Badugar