C program to calculate the sum of the pointer.

 

C program
C PROGRAM

C program to calculate the sum of the pointer

#include<stdio.h>

#include<string.h>

void main()

{    

int*p,sum=0,i;

int x[5]={5,9,6,3,8};

i=0;

 p=x;

clrscr();

printf("\nNOTATION VALUE ADDRESS \n\n");

while(i<5)

{

printf("x[%d] \t %d \t %u \n",i,*p,p);

 sum=sum+*p;

i++,p++;

}

printf("sum=%d",sum);

getch();

}

OUTPUT :

NOTATION VALUE ADDRESS 


x[0] 5 953465056 

x[1] 9 953465060 

x[2] 6 953465064 

x[3] 3 953465068 

x[4] 8 953465072 

sum=31

Process finished.

No comments:

Post a Comment




Copyright Ⓒ 2022 | Mechpedia | All Right Reserved.