Lauri
Explain me this point with examples
BinaryByter
Explain me this point with examples
the go to example is a linked list
Lauri
Give me written example
BinaryByter
Sorry, but i'm too lazy ¯\_(ツ)_/¯
Dima
void* ptr = (void* )object; // polymorphism in c
Dima
Yup
BinaryByter
polymorphism is a bit of a stretch here 😅
Lauri
void* ptr = (void* )object; // polymorphism in c
Can u tell me what this code does
BinaryByter
Can u tell me what this code does
It won't even compile., since object isnt declared
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
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
Can't do Ctrl + f ?
its not the same!
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
Lauri
Irl
klimi
Even my teacher is more stupid than me
Lauri
Yeah sure teachers are very dumb
Dima
It's very hard to understand pointers
they are easy really. they can show the data in a memory for example. this is more about computer basics
BinaryByter
It's very hard to understand pointers
Stop thinking of them as an abstract thing
BinaryByter
Think of them as "positions in memory"
BinaryByter
@Neko_cpp clarify me that
Don't worry about htat, its not too relevant
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
The purpose of group is helping so that's not a favor
Don't worry about the others, i'll help
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); }
BinaryByter
or you tell her the flower pot number
The flower pot number, in this case, is a pointer
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.
Lauri
Explain this
Lauri
That
Lauri
Pi is had a variable
Lauri
7
Badugar
When you'd try to access i from main in foo()
Badugar
Also .. what's a practical use of triple pointers ? 🤔
Dima
fuc*** hell.
Pavel
Yes.
Never seen such a thing in real code
Badugar
Badugar
Never seen such a thing in real code
I've heard of it, but never saw it either.
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)
olli
Would it be achievable with static too ?
Kind of, multiple function invocations would share the object. To access the object outside of the function you need a pointer.
Pavel
Multi dimensional arrays
Oh, so to have 3d array of ints, you need to do this int***?
Pavel
Well vector<vector<vector<...>>>> doesn't sound much better, but at least it's safe :)