When you are using scanf you need to pass the address of the variable you wish to get input for. So you can use the & sign.
Any time you have a variable and want the address you can use the & sign.
If you have a pointer you can use the * sign to access the value. For example:
Code:
int Var = 5;
int *ptr = &Var;
printf("%d\n", *ptr);
*ptr = 1;
printf("%d", Var);
This creates a int variable named Var and sets it to 5. It then creates a pointer which points to the memory location of Var. When you print *ptr it is print the value of what it points to, in this case it is 5.
When you set the value of ptr to 1 you also change Var to 1. Thus, it prints 1 next.
If you just use ptr without the * you would be printing the address it points to, in this case it would be the same as &Var.
Code:
int Var = 5;
int *ptr = &Var;
printf("%p\n%p", ptr, &Var);
- Sean