Tutorials

C Pointers


Pointers and Arrays


Wherever arrays are used pointers can be used over there. 

We will learn about it in this chapter of this C tutorial.

Example:
int a[] = {10,20,30,40,50};

It will be stored in the memory in the following manner:

pointers and arrays by tutorialsinhand.com

 

 

  • The notation of an array is a form of pointer notation.
  • The array name is the starting address of the array in the memory.
  • The base address is the address of the first element.
  • An error can occur if any attempt is made for changing the address of the array.

Example

/*Simple program for showing the relation between arrays and pointers. To find the average of 5 numbers *\

#include<stdio.h>
void main()
{
     float a, sum=0;
     int i;

     int score[] = {35,46,55,56};
     int *pt;
     pt = score;

     for(i=0;i<4;i++)
     sum = sum+*(pt+i);
     a = sum/100.00;
     printf("\n Average score = %f", a);
}

OUTPUT

Average score = 1.92
 

 



Please Share this page
Views : 20
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!