All submissions

Simulate memcpy function Using Pointer Walk

Post inc the dest and src.

#include <stdio.h>

void simulate_memcpy(int *dest, int *src, int n) {
    // Your logic here
    while(n--){
        *dest++ = *src++;
    }
}

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;
}

Solving Approach

in a while loop iterate till n =0  and use post inc of pointers : *src++ : to get the result. 

 

 

Loading...

Input

5 10 20 30 40 50

Expected Output

10 20 30 40 50