Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- double source[5]={1.1,2.2,3.3,4.4,5.5};
- double target1[5];
- double target2[5];
- void copy_arr(double source[], double target1[], int num);
- void print_array(double target[], int size);
- void copy_ptr(double source[], double target1[], int num);
- int main(void){
- copy_arr(source, target1, 5);
- print_array(target1, 5);
- printf("\n");
- copy_ptr(source, target2, 5);
- print_array(target2, 5);
- return 0;
- }
- void copy_arr(double source[], double target1[], int num){
- int i;
- for(i=0; i<num; i++){
- target1[i]=source[i];
- }
- }
- void copy_ptr(double source[], double target1[], int num){
- int i;
- double *ptr = source;
- double *ptr2=target1;
- for(i=0; i<num; i++){
- *ptr2=*ptr;
- ptr2++;
- ptr++;
- }
- }
- void print_array(double target[], int size){
- int i;
- for(i=0;i<size; i++){
- printf("%.1f\n", target[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement