![]() |
| Address Operator in C |
Address Operator:
C presents an address operator '&', which returns the address of a variable while placed earlier than it.This operator may be read as "the address of ", so &age address of age, similarly &sal mean address of sal.
The following program to print the address of variables using address operator.
/* Program to print address of variables using address operator*/
_____________________________________________
#include<stdio.h>
int main( )
{
int age=60;
float sal=1000. 50;
printf ("Value of age%d, Address of age,=%un",age,&age);
printf ("Value of' salf, Address of sal,= %un",sal,&sal);
return 0;
}
_____________________________________________
Output:
Value of age = 60, Address of age = 65524
Value of sal = 1000.500000, Address of sal = 65520
Here we've used %u manage series to print the cope with, but this does not imply that addresses are unsigned integers we have used It considering that there is no precise manipulate series to display deal with Addresses are simply entire numbers. These addresses can be different every time you run your program, it depends upon on which part of memory is allocated by operating device for this program.
The address operator can not be used with a, constant or an expression.
&j; /*Valid, used with a variable*/
&arr[ 1]; /*Valid, used with an array element */
&289; /*Invalid, used with a constant*/
&(j+k); /*Invalid, used with an expression*/
This operator is not new for us because we've already used it in scanf( ) function. The address of variable provide to scanf( ), so that it knows where to write the input value. So now you may recognize why '&.' become, placed before the variable names in scanf( ).
