I wrote the following code to test out pointers to arrays. It's supposed to print the contents of array b, but instead it just prints a string of zeros. Is there some mistake here?
Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
double* pointer(double *p1)
{
int n=10,i;
double b[n],*p2;
p2=&b[0];
for(i=0;i<10;i++)
{
b[i]=*(p1+i)+1;
}
return p2;
}
int main()
{
int n=10,i;
double a[n];
double *p1,*p2;
p1=&a[0];
for(i=0;i<10;i++)
{
a[i]=i;
}
p2=pointer(p1);
i=0;
while(i<10)
{
printf("%f\n",*(p2+i));
i++;
}
return 0;
}