C Memory Address
1. What is a Memory Address?
-
Every variable in C is stored at a specific location in memory.
-
The memory address is the location where the variable’s value is stored.
-
You can find the address using the address-of operator
&.
2. Address-of Operator &
-
The
&operator returns the memory address of a variable.
Example:
Output (example):
%pis used to print pointer/memory addresses in a readable format.
3. Accessing Value Using Pointers
-
A pointer is a variable that stores the address of another variable.
Output:
*ptrgives the value stored at the address.
4. Memory Address of Array Elements
-
Each element of an array has a contiguous memory address.
Output (example):
Notice each int usually occupies 4 bytes, so addresses increment by 4.
5. Key Points About Memory Addresses
-
Use
&to get the address of a variable. -
Use pointers to store and manipulate addresses.
-
Array elements have contiguous addresses in memory.
-
%pis used for printing addresses in pointer format. -
Understanding addresses is crucial for pointers, dynamic memory, and efficient programming.
