Advertisement
horselurrver

Copy

Aug 4th, 2016
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. double source[5]={1.1,2.2,3.3,4.4,5.5};
  3. double target1[5];
  4. double target2[5];
  5.  
  6. void copy_arr(double source[], double target1[], int num);
  7. void print_array(double target[], int size);
  8. void copy_ptr(double source[], double target1[], int num);
  9.  
  10. int main(void){
  11.     copy_arr(source, target1, 5);
  12.     print_array(target1, 5);
  13.     printf("\n");
  14.     copy_ptr(source, target2, 5);
  15.     print_array(target2, 5);
  16.    
  17.     return 0;
  18. }
  19.  
  20. void copy_arr(double source[], double target1[], int num){
  21.     int i;
  22.     for(i=0; i<num; i++){
  23.         target1[i]=source[i];
  24.     }
  25. }
  26.  
  27. void copy_ptr(double source[], double target1[], int num){
  28.     int i;
  29.     double *ptr = source;
  30.     double *ptr2=target1;
  31.     for(i=0; i<num; i++){
  32.         *ptr2=*ptr;
  33.         ptr2++;
  34.         ptr++;
  35.     }
  36. }
  37.  
  38. void print_array(double target[], int size){
  39.     int i;
  40.     for(i=0;i<size; i++){
  41.         printf("%.1f\n", target[i]);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement