address of operator in C
address of operator in C
Note: You will probably get a different address when you run the
above code.
Indirection Operator or dereferencing operator
• * is indirection pointer.
• It is also known as dereferencing pointer.
• It is an Unary operator
• It takes address as an argument
• * returns the Content/Container whose
address is its argument
Indirection Operator
• Let's take a working example.
#include <stdio.h>
int main()
{
int x = 5;
printf(“%d\n",x);
printf("%u",&x);
printf("%u",*&x);
return 0;
}
• Output
5
2686778
5
• The pointer in C language is a variable which
stores the address of another variable.
• This variable can be of type int, char, array,
function, or any other pointer.
• The size of the pointer depends on the
architecture. However, in 32-bit architecture
the size of a pointer is 2 byte.
Pointer Syntax
Here is how we can declare pointers.
int* p;
• Here, we have declared a pointer p of int type.
• For example:
• The effect of calling a function by its name or function pointer is the same. If we are
using the function pointer, we can omit the indirection operator as we did in the
second case. Still, we use the indirection operator as it makes it clear to the user that
we are using a function pointer.
Example
#include <stdio.h>
int add(int,int);
int main()
{ Output:
int a,b;
int (*ip)(int,int);
int result;
printf("Enter the values of a and b : ");
scanf("%d %d",&a,&b);
ip=add;
result=(*ip)(a,b);
printf("Value after addition is : %d",result);
return 0;
}
int add(int a,int b)
{
int c=a+b;
return c;
}