关于二维数组复制数值的问题
明明赋值错误了,为什么显示正确的结果#include<stdio.h>
double copy_arr(double *,double *,int n);
double copy_ptr(double *,double *,int n);
int main(void)
{
double source[2][5]={{1.2,3.2,2.2,4.2,5.2},{2.2,4.2,12.2,4.2,1.2}};
double target1[2][5];
double target2[2][5];
copy_arr(source,target1,10);
printf("\n");
copy_ptr(source,target2,10);
}
double copy_arr(double *source,double *target1,int n)
{
int i,total=0;
for(i=0;i<n;i++)
{ //这里为什么会显示正确的结果,明明是赋给target1[0]-target1[9],为什么结果会和target2[0][0]-target2[1][4]的值一样
target1[i]=source[i];
printf("%5.1f",target1[i]);
}
}
double copy_ptr(double *source,double *target2,int n)
{
int i,total=0;
for(i=0;i<n;i++)
{
*(target2+i)=*(source+i);
printf("%5.1f",*(target2+i));
}
}
double copy_arr(double *,double *,int n);
double copy_ptr(double *,double *,int n);
int main(void)
{
double source[2][5]={{1.2,3.2,2.2,4.2,5.2},{2.2,4.2,12.2,4.2,1.2}};
double target1[2][5];
double target2[2][5];
copy_arr(source,target1,10);
printf("\n");
copy_ptr(source,target2,10);
}
double copy_arr(double *source,double *target1,int n)
{
int i,total=0;
for(i=0;i<n;i++)
{ //这里为什么会显示正确的结果,明明是赋给target1[0]-target1[9],为什么结果会和target2[0][0]-target2[1][4]的值一样
target1[i]=source[i];
printf("%5.1f",target1[i]);
}
}
double copy_ptr(double *source,double *target2,int n)
{
int i,total=0;
for(i=0;i<n;i++)
{
*(target2+i)=*(source+i);
printf("%5.1f",*(target2+i));
}
}