Question: Pointer

Okay, so I have been doing more and more tutorials and I have been learning alot. However, I had a couple of questions:

#1. Can you use a pointer to change a var of a class?

#2. If you can do the above, could anyone show me an example of: (x = 0; until the pointer changes it to 1)

1
2
3
4
5
while(x==1)
          {
           Do Something

          }


Thanks for your guys help.
closed account (Lv0f92yv)
Do you mean can you use a pointer to change the value of a variable that is declared inside a class? Yes.

1
2
3
4
5
while ( x == 0 )
{
   int *ptrX = &x; //assuming x is an int here
   *ptrX = 1; //assign 1 to x
} //this now exits, since x!= 0. 

Is this: void attack(); a declaration of a function or the calling of a function? Could it be either?
Last edited on
Is this: void attack(); a declaration of a function or the calling of a function? Could it be either?


It's a declaration.
It's a declaration as long as it's outside another function. When it's inside a function, it's called a "way too long calling of a function".

-Albatross
Last edited on
Does a pointer hange the variable? I know that it gets the address but for all intents and purposes does the old var become the new var?
closed account (Lv0f92yv)
No. A pointer is an alternative way to access data. Using a pointer to reference a variable means that it can change the contents at the address to which it points. Check out the pointer tutorial on this site:

http://www.cplusplus.com/doc/tutorial/pointers/
Topic archived. No new replies allowed.