#include <stdio.h>
void copy_arr(double target[],double source[],int n)
{
for(int i=0;i<n;i++)
{
target[i]=source[i];
}
}
void copy_ptr(double target[],double source[],int n)
{
double *p=target;
for(int i=0;i<n;p++,i++)
{
*p=source[i];
}
}
void copy_ptrs(double target[],double source[],double *ptr)
{
double *ptr1=target,*ptr2=source;
for(;ptr2<ptr;ptr1++,ptr2++)
{
*ptr1=*ptr2;
}
}
int main()
{
double source[5]={1.1,2.2,3.3,4.4,5.5};
double target1[5];
double target2[5];
double target3[5];
copy_arr(target1,source,5);
copy_ptr(target2,source,5);
copy_ptrs(target3,source,source + 5);
for(int i=0;i<5;i++)
{
printf("%.1f ",target1[i]);
printf("%.1f ",target2[i]);
printf("%.1f ",target3[i]);
printf("\n");
}
}
原文:https://www.cnblogs.com/younger-man/p/11636551.html