Page 1 of 1

Stupid Fun Video about pointers

PostPosted: Sat Oct 15, 2011 5:38 am
by EvanBlack
I found this lol, wow, its about pointers in C. Hope it helps some of you XD

http://www.cs.stanford.edu/cslibrary/PointerFunC.avi


HitoV wrote:Here's another resource about pointers that is much more in depth. Makes my head spin a bit less :D

http://home.earthlink.net/~momotuk/pointers.pdf

Re: Stupid Fun Video about pointers

PostPosted: Sat Oct 15, 2011 1:12 pm
by Game A Gogo
This is great! +1
It helped me understand what I already thought I understood even better :) thanks a lot!

Re: Stupid Fun Video about pointers

PostPosted: Sat Oct 15, 2011 1:37 pm
by jimmynewguy
I kind of understand this a little better, I'm just not sure how it "helps" me all too much in GE :lol: I guess I just don't fully understand it's use. Never took a programming course or any of the sort, just learned GE from GE-ers and trail and error. Enlighten me!

Re: Stupid Fun Video about pointers

PostPosted: Sat Oct 15, 2011 2:04 pm
by Game A Gogo
Well I don't see a purpose in them yet, but I am not advanced enough to need to use them either!

Re: Stupid Fun Video about pointers

PostPosted: Sat Oct 15, 2011 4:01 pm
by Hblade
Thanks Evan! :)

Re: Stupid Fun Video about pointers

PostPosted: Sat Oct 15, 2011 5:52 pm
by SuperSonic
Haha, this is funnyXD

Re: Stupid Fun Video about pointers

PostPosted: Sat Oct 15, 2011 7:33 pm
by EvanBlack
Pointers allow you to create things like linked lists and allow you to access data without making a copy of it by referencing it directly.

Pointers are the most useful thing ever especially for gamedev. You use pointers all the time in your games and probably don't even realize it.

Everytime you change a variable in an actor you are first using the actor pointer to access the actor structure.

CreateActor() and getclone() both return pointers to the Actor's data structure in memory.

You could create an actor that moves in the same x as another actor by using a pointer.

Code: Select all
double *p_x; // global pointer

//set the pointer to the address of the actors x,  & gets the memory address
p_x = &MyActor1->x;

//set the other actors x to the value of the first actor using the pointer, * dereferences the pointer
MyActor2->x = *p_x;




Here is an example.

Re: Stupid Fun Video about pointers

PostPosted: Sat Oct 15, 2011 8:07 pm
by jimmynewguy
:P Try dragging these ones around!

Re: Stupid Fun Video about pointers

PostPosted: Sat Oct 15, 2011 8:10 pm
by EvanBlack
HAHAHA Thats awesome. Really cool. I hope you guys understand the importance and use of pointers now XD

Re: Stupid Fun Video about pointers

PostPosted: Sun Oct 16, 2011 12:14 pm
by Jagmaster
Thanks for the video, I love claymations! This was funny!

Re: Stupid Fun Video about pointers

PostPosted: Tue Oct 18, 2011 11:01 pm
by HitoV
This is great! I understand how they work and what they do but I don't understand why you would use them over other ways of getting the same values... :?

In the example, you have draw event in myActor1 as x = *p_x;
Using:
x = myActor2.x;
in the same draw event gives you the same thing.

I don't really see a use for them except for maybe getting a private variable out of the scope of a class. (which of course means nothing in ge)

What I do find confusing is how p_x updates with the... umm... hold on, I think a light bulb went off :shock:
How does it update even though its called in create actor which is a one shot type!?! AHHH! So that is what you mean by "gets the address of x and assigns it to the pointer." It literally references directly from the memory.
Son of a gun that's cool! Thanks! And thanks for the video, that was hilarious and informative :D

Re: Stupid Fun Video about pointers

PostPosted: Wed Oct 19, 2011 1:04 am
by EvanBlack
Yeah lol and there are many many more reasons to use pointers instead of variables. Such as if you want to access an array.

Say you have an array of like 5 Million integers and you need to pass that array to a function. Instead of copying that huge array you can just pass a reference to it like this.

Code: Select all
int Array[5000000];

void function(int* pIntegers)
{
     //do stuff
}


function(&Array);



There are really many many reasons to use pointers. You just have to be creative and think about what you can do with them.

And yes, the address is a memory address.

* = dereferences an address, or gets the information stored at an address in the memory.

& = reference address, or gets the address of the information stored in the memory.

You can even get the address of a pointer and assign it to a double pointer.


Code: Select all

int X;
int A;

int *pX; //my integer pointer

int **ppX; //my pointer to an integer pointer

int ***pppX; // my pointer to and integer pointer pointer

X = 3;

pX = &X;

ppX = &pX;

pppX = &ppX;


A = *pX;  // A = X

A == 3 // or A == X

A == **ppX // A == 3

***pppX = 22; // X = 22

pX = &A;

X == 22;

A == 3;

***pppX == 3; //pppX  points to ppX which points to pX which points to A which has the value of 3

***pppX = 55;

X == 22;

A == 55;



Kind of confusing when you start putting more layers on but also know that pointers can be dereferenced a more readable way.

Continuing from above:
Code: Select all

pppX->ppX->pX->A == 55;


Re: Stupid Fun Video about pointers

PostPosted: Sat Oct 22, 2011 9:16 pm
by HitoV
Here's another resource about pointers that is much more in depth. Makes my head spin a bit less :D

http://home.earthlink.net/~momotuk/pointers.pdf

Re: Stupid Fun Video about pointers

PostPosted: Sat Oct 22, 2011 9:36 pm
by EvanBlack
HitoV wrote:Here's another resource about pointers that is much more in depth. Makes my head spin a bit less :D


AWESOMELY GOOD STUFF!! There is even information in that I want to learn more about lol. The internet is a great resource for learning. If compiled into a better list then it would be the best.

I am going to post that link at the top