I've always never fully understood pointers. I'm writing this dinky blackjack game for fun on the side of my studies, and I need confirmation that this use of pointers is legitimate so I can fully understand what they do.
currently this is an example of the program and function i'm using:
void dealcard(int hand){
hand+=rand()%10+2;
}
int()main{
int playerHand;
...
*blackjack stuff*
...
if(hit){
deal(hand);
}
now if I'm correct, the above would not work as I intend because the function uses a copy of the variable that is cleared before it can be applied to the original, and hand
would never be changed.
if I changed it to something like
int b;
int *hand;
hand=&b;
and changed the function declaration to include the *
, then that would be correct.
I'm really trying hard to understand pointers and i'd appreciate any help or confirmation on this so I can understand the basic usefulness of them.