men, I was about to try and explain pointers... but really that binky video is awesome ![]()
Pointers are like directions to somewhere...
Think of one of your friend's house. That house has an adress, right ? that house has some content, meaning, people live there right?
So when you set a pointer , you set the directions for that house...
you want to know what's inside the house ? use *
you want to know the adress of the house ? use &
The thing with pointers is that they need to point to somewhere valid. To reserve space to build a house...you need to buy that space... that's what malloc does... it just buys you some space.
If you give me an adress for a house that's not there ... invalid
it's not complicated... but don't worry, it's neither intuitive at first ![]()
little example:
this is how you declare a pointer: house* direction;
let's buy a house... so we need to buy space for the house remember ? direction = (house*)malloc(sizeof(house))
wow... what was that?
malloc reserves space remember? the big question is... how much space ? that's what sizeof tells it to... the size of a house. the (house*) part is one you don't need to bother... just substitute house with whatever variable type you need
want to know what's inside of a house ?
insideHouse = *house;
want to know what's the adress of that new house?
adress = &house;
simple isn't it
sorry that I didn't explain it as well as binky tough ![]()