What is Address Operator in C

what is address operator in c
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( ).

Conclusion:-

Through this article we have learned about 'address operator' in detail, with the help of which we can say that address operator is represented in C by this symbol '&' and it placed before the variable to find the address of that variable.
Post a Comment (0)
Previous Post Next Post