Hi! I have watched quite a few C++ tutorial videos and a few text explanations, and one of the parts that always confuse me are pointers! But I may understand them. Tell me if this is how I could think of a pointer.
So say we had a block of code with 2 variables, one which is just a normal int variable, and one that is a pointer int that points to the memory address of health:
1 2
int health = 80;
int *health2 = &health;
So basically, with health2 pointing to the memory address, health2 is able to modify the health variable because it is pointing to the memory address of health? If so then I understand pointers but could someone please give me a hand with this. I have heard that it is quite a confusing topic for many people but hopefully when I grasp it I will understand how they work!
Check out this code and tell me if they will both do the same:
CODE PIECE 1:
int health = 80;
CODE PIECE 2:
1 2 3
int health;
int *health2 = &health;
*health2 = 80;
Would these two code pieces do the same thing? Thanks!