路过。。
程序代码:
#include <stdio.h>
void copy_ptr(double *,double *,int);
int main(void)
{
double source[8]={1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8};
double target[3];
//int i;
copy_ptr(&source[2],target,3);
return 0;
}
void copy_ptr(double *source,double * target,int n)
{
int i;
puts("\n==== Before the copy operation =====");
printf("*source* is AT: %p, *target* is AT: %p\n", source, target);
for(i=0;i<n;i++)
*target++ = *source++;
puts("\n==== Middle in the operation =====");
printf("*source* is AT: %p, *target* is AT: %p\n", source, target);
for(i=0;i<3;i++)
printf("%.2lf ",*target++);
putchar('\n');
puts("\n==== End of the operation =====");
printf("*source* is AT: %p, *target* is AT: %p\n", source, target);
}
程序代码:$ gcc -o test_double_cp double_cp.c $ ./test_double_cp.exe ==== Before the copy operation ===== *source* is AT: 0022FF20, *target* is AT: 0022FEF8 ==== Middle in the operation ===== *source* is AT: 0022FF38, *target* is AT: 0022FF10 1.10 2.20 3.30 ==== End of the operation ===== *source* is AT: 0022FF38, *target* is AT: 0022FF28
程序代码:$ gcc -O2 -o test_double_cp double_cp.c $ ./test_double_cp.exe ==== Before the copy operation ===== *source* is AT: 0022FF08, *target* is AT: 0022FF38 ==== Middle in the operation ===== *source* is AT: 0022FF20, *target* is AT: 0022FF50 0.00 0.00 0.00 ==== End of the operation ===== *source* is AT: 0022FF20, *target* is AT: 0022FF68
程序代码:zhd@TISYANG ~/source/temp_cpp $ gcc -O3 -o test_double_cp double_cp.c zhd@TISYANG ~/source/temp_cpp $ ./test_double_cp.exe ==== Before the copy operation ===== *source* is AT: 0022FEF8, *target* is AT: 0022FF28 ==== Middle in the operation ===== *source* is AT: 0022FF10, *target* is AT: 0022FF40 0.00 1.#R 0.00 ==== End of the operation ===== *source* is AT: 0022FF10, *target* is AT: 0022FF58

