সোমবার, ১৮ অক্টোবর, ২০১০

32.The & and * Operators in POINTER

Consider the declaration,

int i=5;

This declaration tells the C compier to

  • Reserve space in memory to hold the integer value.
  • Associate the name i with this memory location.
  • Store the value 3 at this location.
We may represent i's location in the memory by the following memory map:

we see that the computer has selected memory location 6589 as the place to store the value 5. This location number 6589 is not a number to be relied upon, becuse some othertime the computer may choose a different location for storring the value 5. The important point is, i's address in memory is a number.

We can print this adderss through the following program:

#include<stdio.h>
main( )
{
int i=5;
printf("\n Address of i=%u", &i);
printf("\n Value of i=%u", i);
getch();
}

The output of the above program would be:

Address of i=6589
Value of i=5

Now look at the first printf( ) statement carefully. The '&' operator used in this statement is C's 'address of' operator. The expression &i returns the address of the variable i, which in this case happens to be 6589.

The other pointer operator available in Cis '*', called 'value at address' operator. It returns the value stored at a porticular address. The 'value at address' operator is also called an 'indirection' operator.

post by Arnob.
taken from 'Understanding pointers In C' 

২টি মন্তব্য: