C - Memory Address
A memory address refers to the location in memory where a variable or data is stored. Each variable in C has its own memory address, which can be accessed using the address-of operator (&). The memory address is represented as a hexadecimal value.
To print the memory address of a variable, you can use the %p format specifier in printf() and pass the address of the variable using the address-of operator. Here's an example:
#include <stdio.h>
int main() {
int number = 42;
float floatValue = 3.14;
printf("Memory address of number: %p\n", (void *)&number);
printf("Memory address of floatValue: %p\n", (void *)&floatValue);
return 0;
}
In this example, the memory addresses of the number variable and the floatValue variable are printed using %p format specifier. The (void *) type casting is used to ensure that the address is correctly printed.
When you run the program, you will see the memory addresses displayed as hexadecimal values.
Keep in mind that the memory addresses can vary each time you run the program, as they depend on the specific execution environment.
Understanding memory addresses is important for tasks such as passing variables by reference, working with pointers, and dynamic memory allocation.