+ 1
Help
int score=5; int *scorePtr; scorePtr=&score. third line-the address of score is assigned to the variable scorePtr, does it means that the address of the variable 5 is assigned to the scorePtr. and what if i changed (int *scorePtr) to (int *score) will it make any difference. thank u.
2 Answers
0
1) scorePtr = &score
it's more the other way, the pointer 'scorePtr' points towards the address of variable 'score'.
you dont assign addresses to pointers. you assign pointers to addresses.
hope that makes sense.
2) you want to change the code so it looks like:
int score = 5;
int *score;
?
this will not compile. in the second line you try to declare a variable (a pointer to a memory that can store an Integer) called 'score'. but there is already a variable called the same = error.
* <- it's not a part of the variable name, it's a partof the variable type.
0
yes you are correct the memory address of score is the value stored by scorePtr. secondly yes