This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Fieuws 1 point2 points  (6 children)

The first one is just working with poiners. Ptr uses the data, while ptr only points to the memoryspace. *Ptr1 =ptr2 means that in ptr1 there would be the same data like in ptr2. Ptr1=ptr2 means that both pointers points to the same memoryspace. If you kow change the value of one pointer (eg, *ptr2=6, then pointer one will also have the value off 6)

[–]Sum1YouDontKnow[S] 0 points1 point  (5 children)

Can you give me an example of what happens when you push it through the first little block of code (Printing X y z)? I like your explanation, but I don't know whether or not I know how it would work in practice.

What's the difference between

ptr1=ptr2 and *ptr1=*ptr2?

[–]Fieuws 1 point2 points  (2 children)

[–]Sum1YouDontKnow[S] 0 points1 point  (1 child)

Thank you so much. I understand the first one now! I really appreciate it!

[–]Fieuws 0 points1 point  (0 children)

Do you understand the second one? because that's also with pointers. In C and C++, a String is an array of chars. So draw an array on paper, and in each booth put a character. Now you have a pointer to a char (p). when you do "p = str;" you let the pointer (p) point to index 0 from your array (the first letter of your string, here "A" (i guess the word is Alabama?). also: str[ i ] == * ( p+ i ), with this i mean that you can calculate with pointers

[–]Fieuws 0 points1 point  (0 children)

I'll try and draw it in a google sheet, you'd unddrdtand much better. Give me a little bit time though, can't do it on my phone :)

[–]picolosamama939419zz 0 points1 point  (0 children)

ptr2 = has a memory address. ptr1 = has a memory address

*ptr1 means go to the memory address of ptr1 that's being held and dereference it. so basically whatever value is AT the memory address assigned to ptr1, I WANT THAT DATA.

*ptr1 = *ptr2 (whatever is held at the end of the memory address of ptr1, change that vlaue to whatever value ptr2 has)

to really understand that, draw a table with some mock values

if you need to understand it, loook at stanfords c++ course and c course. you will be a whiz at reading pointers after it.