Sunday, November 27, 2011

Output & Errors

void main()
{
  char s[ ]="man";
  int i;
  for( i=0 ; s[ i ] ; i++ )
   printf("\n%c %c %c %c" , s[ i ], *(s + i), *(i + s), i[s]);
}


Output:

m m m m
a a a a
n n n n

Since, 's' contains the base address and 'i' is the index i.e the address after 'i' locations from the base address. Internally C compiler converts the statement s[ i ] into the form *(s + i), which equals *(i + s) or can also be written as i[s].

Get Updates on Facebook and Twitter also.

0 comments:

Post a Comment