0

the difference between pointer & address, help me please?

4th Feb 2017, 9:34 AM
omar
omar - avatar
3 Respuestas
+ 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;
4th Feb 2017, 11:05 AM
Nedim Kanat
Nedim Kanat - avatar
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
4th Feb 2017, 9:56 AM
iSlam
iSlam - avatar
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.
4th Feb 2017, 9:58 AM
Bill
Bill - avatar