RE: [C++] Understanding Pointers and Their Useage 03-14-2014, 02:32 AM
#9
Thanks for the making this tutorial. Here a few things to point out
To be precise, variable is not an object. variable is just an alias of memory address.
Once program is compiled, variable will be a mere memory address and the variable
name is lost.
All the variable are the same. It has binary-represented-value and address.
Variable type provide the meaning to those binary-represented value. Same
binary representation may mean different thing for different data type.
The following example shows that same binary representation has different
meaning based on the data type.
Pointer is no different from other variable. It does not need to hold
memory address. However, like other data type. It adds the meaning
of the value. So when people see pointer variable, they confidently
assume that it holds memory address.
It is also true to other variable type. It also have ability to hold
memory address. For example:
Quote:A variable is an object that hold's a value. A integer variable holds a number.
A character variable holds a letter. A pointer is a variable that holds a memory address.
To be precise, variable is not an object. variable is just an alias of memory address.
Once program is compiled, variable will be a mere memory address and the variable
name is lost.
All the variable are the same. It has binary-represented-value and address.
Variable type provide the meaning to those binary-represented value. Same
binary representation may mean different thing for different data type.
The following example shows that same binary representation has different
meaning based on the data type.
Code:
int main()
{
float a = 0.25f; // assuming 4 bytes
int b = *((int*)&a); // assuming 4 bytes
std::cout << a << std::endl; // 0.25
std::cout << b << std::endl; // 1048576000
}Pointer is no different from other variable. It does not need to hold
memory address. However, like other data type. It adds the meaning
of the value. So when people see pointer variable, they confidently
assume that it holds memory address.
It is also true to other variable type. It also have ability to hold
memory address. For example:
Code:
int main()
{
float a = 0.25f;
int b = (int)&a;
*((float*)b) = 2.25;
std::cout << a << std::endl;
}
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)