58. Simulate memcpy function Using Pointer Walk

Discussions1
Log in to post comments and replies.
You
supreethsupri
supreethsupriApr 07 2026

#include <stdio.h>


 

void simulate_memcpy(int *dest, int *src, int n) {

    // Your logic here


 

    while(n){


 

*dest=*src;

dest++;

src++;

n--;


 

    }

}


 

int main() {

    int n;

    scanf("%d", &n);


 

    int src[100], dest[100];


 

    for (int i = 0; i < n; i++) {

        scanf("%d", &src[i]);

    }


 

    simulate_memcpy(dest, src, n);


 

    for (int i = 0; i < n; i++) {

        printf("%d", dest[i]);

        if(i < n-1){

           printf(" "); 

        }

    }


 

    return 0;

}

0