If you have any query feel free to chat us!
Happy Coding! Happy Learning!
In C language, the address operator (&) is used to obtain the memory address of a variable. The dereference operator (*) is used to access the value stored at a memory address.
The address operator (&) is placed before the variable name, and it returns the memory address of that variable. For example, if you have an integer variable x
, the expression &x
returns the memory address of x
.
The dereference operator (*) is placed before a memory address, and it returns the value stored at that memory address. For example, if you have a pointer variable p
that holds the memory address of an integer variable x
, the expression *p
returns the value stored in x
.
Here's an example:
Copy code
#include <stdio.h>
int main()
{
int x = 10;
int* p = &x;
printf("The value of x is: %d\n", x);
printf("The memory address of x is: %p\n", &x);
printf("The value stored at address p is: %d\n", *p);
return 0;
}
In this example, x
is an integer variable with the value of 10, p
is a pointer variable that holds the memory address of x
, and the printf
statements print the value of x
, the memory address of x
, and the value stored at the memory address held by p
.
It's also important to mention that *
operator is also called Indirection operator, and it can be used to dereference a pointer variable to access the value stored in that memory location.
Comments: 0