as

Thursday 13 November 2014

Pointers and Arrays


Arrays are special type of pointer.

When we declare an array, the name of array contains the address of array's first element.

#include <stdio.h>

void squares(int *a, int size)
{
int i;
for (i=0;i<size;i++)
{
*(a+i) = *(a+i) * *(a+i);
}
   
}

int main()
{
   int myarray[3] = {2,3,4};
   int i;

 //both statements will print same address value

  printf("myarray contains %u \n",myarray);
  printf("&myarray contains %u \n",&myarray);

  squares(myarray,3);

  for(i=0;i<3;i++)
   printf("%d   ", myarray[i]);
}



No comments:

Post a Comment

Leave your valuable feedback. Your thoughts do matter to us.

Sponsored Links

Popular Posts

Comments

ShareThis