0
the difference between pointer & address, help me please?
3 Réponses
+ 1
// a normal number
int number = 5;
// a pointer
int *pointer = new int;
// pointer pointing to address of number 5 (& means reference)
// by doing this it will get number 5 by accessing
// its address which is located somewhere in the memory
pointer = &number;
cout << "number is: " << number << endl;
cout << "address is: " << &number << endl;
cout << "Getting number with pointer: " << *pointer << endl;
0
a pointer is a normal variable and its value is an address so you can think of it as a pot filled with water , here the pot is the pointer itself which can be filled with any water but the volume of water itself is the same
0
a pointer stores an address in memory.
//has the value of 5, and in memory it has an address
//we don't know the address but lets say it's 1234567
int myInt = 5;
//now let's create an int pointer, which doesn't store an
//integer, it stores the address in memory where the integer
//value is
int* pointerToMyInt;
//now let's assign our pointer a value by assigning the pointer
//the address of an integer variable
pointerToMyInt = &myInt;
now pointerToMyInt stores the address of myInt, which we are pretending is 1234567. The value at that memory address is 5, which is the value of myInt. if we wanted to get the value of myInt from the pointer, we would have to dereference it which is done by using the * key. in this case it would be *pointerToMyInt, which would return the value 5.