Online Snippets Library

Create C Program to copy an array to another array

To copy an array to another array We need to iterate first array and copy each element to another array.

C Program
#include <stdio.h>

int main() {
   int originalArray[5] = {1, 2, 3, 4, 5};
   int copiedArray[5];
   int loop;
   
   for(loop = 0; loop < 5; loop++) {
      copiedArray[loop] = originalArray[loop];
   }
   printf("originalArray -> copiedArray \n");
   
   for(loop = 0; loop < 5; loop++) {
      printf("   %2d        %2d\n", originalArray[loop], copiedArray[loop]);
   }

   
   return 0;
}

Output

originalArray -> copiedArray 1 1 2 2 3 3 4 4 5 5