Address Operator



Address operator (&) is used to get the address of the operand. For example if variable x is stored at location 100 of memory; &x will return 100.

This operator is used to assign value to the pointer variable. It is important to remember that you MUST NOT use this operator for arrays, no matter what data type the array is holding. This is because array identifier (name) is pointer variable itself.

When we call for ArrayA[2]; ‘ArrayA’ returns the address of first item in that array so ArrayA[2] is the same as saying ArrayA+=2; and will return the third item in that array.

Pointer Assignment

The values to the pointer variable can be assigned by means of following general syntax.

Syntax:-
Pointer var =&variable;
Ex:- int a=5,*p;
P=&a;

Accessing Pointer Variable

If a pointer is pointing to a variable then value of that variable can be access by using the pointer.

*ptr_name.
Ex: - int a=5,*p;
p=&a;
printf(“%d”, *p);

Call by Value

If a function is called by passing a variable or a value then such a function call is called as call by value. Here, the value of the variable is passed as argument as a function so the operation performed by that function on that value is not reflected back on the original variable.

Ex.
  main ()
   {
     int a=5;
     printf (“%d”, a);
     change (a);
     printf (“%d”, a);
   }

Call by Reference

If a function is called by passing address of a variable then such a function call is called as call by reference. Here we are passing address of variable as argument to the function.

So the operation performed by that function by using that address is actually performed on the original variable.

Ex:
  main()
    {
       Int a=5;
       printf(“%d”,a);
       change(&a);
       printf(“%d”,a);
    }