x <- this is SAME as int *x but without the int in front. You can't just get the address the pointer has stored in it by adding a int in front.. cuz int in front can only be used once! and thats to declare pointer so just x without a star in front means Address its holding that its points too.
You can't understand pointers if you don't understand their purpose..
Pointers only have one purpose thats to get stuff BACK as functions.. but functions get 1 stuff back pointers can get ALOT more!
Example when I gotta use em? Okay here it is. main(){ int a = 4; int b = 6; changeNumbers(a, b); Whats a and b on this line? they should be 100 and 200 right? WRONG they are still 4 and 6 :) why?? cuz when you pass stuff in functions and function stops working. they get DELETED! } void changeNumbers(int a, int b){ a = 100; b = 200; }
Here is pointer example.. main(){ int a = 4; int b = 6; changeNumbers(&a, &b); Whats a and b on this line? they are 100 and 200 see there u go you mastered pointers } void changeNumbers(int *a, int *b){ *a = 100; *b = 200; }
why did I use &a and &b you may by wondering.. the thing is.. I dont want the changeNumbers function to know a and b's values I want it to know their address! address IS GLOBAL when used with pointers!
Address is another name for RAM (random access memory) thats right thats the same RAM in your computer..
if you mess with pointers in a bad way.. you could change numbers in different programs! they could be dangerous if not used automatically like I did in my example I used automatically
They're mainly used with functions. Since variables within a function are terminated when that function returns, you use a pointer to directly manipulate the address of that variable so that any changes made to the variable in that function are carried over when the function returns.
Example:
int myFunction(int *pMyPointer);
When that function is called, you pass the address of your argument(s) instead, like so:
im so dumb that you going to have to use fingers and swearing...i hate pointers ... fu*%en 'asterisk '
EvolutionXEngine 11 months ago
Great man....I understand them now!
Thanks.
burekus 1 year ago
Treat me like a CHILD and we will NEVER get real. ahha
freeadplanet 1 year ago
This is destined to be a classic...
jwillisgod 1 year ago
ahahhaha
VietPho 3 years ago
SSpoke: Great examples. thank you
louisgjordan2 3 years ago
When dynamically allocating memory, don't forget to delete kids! :P
UnresolvedExternal 3 years ago
The way this video explains people will get mixed up more then often this is how I mastered pointers in 1 day.
int *x; <- pointer (Address holder) not pointing to anything but address holder goes up by int!).
*x <- seems same as the first one but it has no int datatype in front! that means it holds the value its pointing too!
&x <- address to pointer? NO this is address OF pointer it self!
so whats x?
sspoke 3 years ago
x <- this is SAME as int *x but without the int in front. You can't just get the address the pointer has stored in it by adding a int in front.. cuz int in front can only be used once! and thats to declare pointer so just x without a star in front means Address its holding that its points too.
You can't understand pointers if you don't understand their purpose..
Pointers only have one purpose thats to get stuff BACK as functions.. but functions get 1 stuff back pointers can get ALOT more!
sspoke 3 years ago
sspoke 3 years ago
sspoke 3 years ago
why did I use &a and &b you may by wondering.. the thing is.. I dont want the changeNumbers function to know a and b's values I want it to know their address! address IS GLOBAL when used with pointers!
Address is another name for RAM (random access memory) thats right thats the same RAM in your computer..
if you mess with pointers in a bad way.. you could change numbers in different programs! they could be dangerous if not used automatically like I did in my example I used automatically
sspoke 3 years ago
I've already explained their use below and how to use them. :)
Spunky48 3 years ago
thanks for explaining it,
nicely explained :)
cptBraver 3 years ago
very funny, but pointers are also initialized with values like all variables, so it's not pointing to nothing...
sxfreak 3 years ago
Initialization is optional, you can choose not to initialize a pointer but it's dangerous. Uninitialized pointers are called "wild pointers".
Spunky48 3 years ago
haha
animorten 3 years ago
I understand what pointers are now actually.
but why use them? I dont know =/...
ThunderDonkey 4 years ago
They're mainly used with functions. Since variables within a function are terminated when that function returns, you use a pointer to directly manipulate the address of that variable so that any changes made to the variable in that function are carried over when the function returns.
Example:
int myFunction(int *pMyPointer);
When that function is called, you pass the address of your argument(s) instead, like so:
myFunction(&myVariable);
Any changes to that variable will carry over.
Spunky48 3 years ago
u might want to put this in ur description
cptBraver 3 years ago
Good call. Done. :)
Spunky48 3 years ago
no comment
fatrolando99 4 years ago
LOL!
prutalete 4 years ago 2