For :
int *a;
a
is an address where an integer can be stored.
&a
is an address where a is stored.
Then, where is &a
stored?
And, where is &(&a)
stored?
And, where is &(&(&a))
stored?
Where does this storing of addresses stop?
A pointer is a variable that stores the address of another variable. Unlike other variables that hold values of a certain type, pointer holds the address of a variable. For example, an integer variable holds (or you can say stores) an integer value, however an integer pointer holds the address of a integer variable.
Answer: A pointer is similar to a variable but the difference is that pointers store the address of a location in memory and the variable stores the value. In other words, we can say, a pointer is used to reference a location in the memory.
Pointers are arguably the most difficult feature of C to understand. But, they are one of the features which make C an excellent language. In this article, we will go from the very basics of pointers to their usage with arrays, functions, and structure.
A pointer is a variable that stores the memory address of another variable as its value. A pointer variable points to a data type (like int ) of the same type, and is created with the * operator.
If you don't explicitly write &a
it will not be stored anywhere. If you do write then the address will be computed and stored either in an unnamed variable (temporary) or a named varible you write.
For example:
functionCall( &a ); // address will be in a temporary variable used for passing the parameter
int** b = &a; // address will be stored in variable b
otherFunctionCall( &&a ); // illegal, since &a is an expression operator & can't be applied to it
&a
is a constant.
&(&a)
is illegal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With