C Program to Copy Elements from One Array to Another

Subject: PPS (Programming for Problem Solving)

Contributed By: Sanjay

Created At: February 3, 2025

Question:


Write a C Program to Copy Elements from One Array to Another

Explanation Video:

Custom Image

Explanation:

 

We copy each element from the source array to the destination array using a loop.

Source Code:
#include <stdio.h>

int main() {
    int arr1[] = {10, 20, 30, 40, 50};
    int n = sizeof(arr1) / sizeof(arr1[0]);
    int arr2[n];

    for (int i = 0; i < n; i++)
        arr2[i] = arr1[i];

    printf("Copied Array: ");
    for (int i = 0; i < n; i++)
        printf("%d ", arr2[i]);

    return 0;
}
Output:
Copied Array: 10 20 30 40 50
Share this Article & Support Us: