You can't directly do array2 = array1, because in this case you manipulate the addresses of the arrays (char *) and not of their inner values (char).

What you, conceptually, want is to do is iterate through all the chars of your source (array1) and copy them to the destination (array2). There are several ways to do this. For example you could write a simple for loop, or use memcpy.

That being said, the recommended way for strings is to use strncpy. It prevents common errors resulting in, for example, buffer overflows (which is especially dangerous if array1 is filled from user input: keyboard, network, etc). Like so:

Copy// Will copy 18 characters from array1 to array2
strncpy(array2, array1, 18);

As @Prof. Falken mentioned in a comment, strncpy can be evil. Make sure your target buffer is big enough to contain the source buffer (including the \0 at the end of the string).

Answer from aymericbeaumet on Stack Overflow
🌐
Quora
quora.com › How-do-you-copy-an-array-of-integers-into-another-array-in-the-C-programming-language
How to copy an array of integers into another array in the C programming language - Quora
Answer (1 of 4): Well , it's very easy ! Step 1 : Define the other array Step 2 : Simply insert elements of previous array into the new one Example : Hope it helps !
Discussions

Why in C arrays can be copied one element at a time using loop but entire array cannot be copied at one stroke
memcpy(dst,src,size); More on reddit.com
🌐 r/C_Programming
38
16
August 13, 2023
Copying Array into another array
Simply, I would like to copy an array A and past it in array B. I have an array_1={1,2,3,4,5}; and I have an array_2={6,7,8,9,0};. I am not able to use strcpy or memcpy in Arduino. int array_1[5]={1,2,3,4,5}; //Array 1 with 5 elements int array_2[5]={6,7,8,9,0}; //Array 2 with 5 elements void ... More on forum.arduino.cc
🌐 forum.arduino.cc
9
0
October 22, 2014
c - Fast way to copy an array - Stack Overflow
If it is just to swap two arrays ... with the currently used array address (double-buffering). Eugene Sh. – Eugene Sh. 2015-11-11 21:32:13 +00:00 Commented Nov 11, 2015 at 21:32 ... Note that your title indicates "swapping" arrays, but your actual question only implies "copying" one array to another... More on stackoverflow.com
🌐 stackoverflow.com
Is there a function to copy an array in C/C++? - Stack Overflow
Instead you should either use one ... very close to built-in arrays, but with value semantics like other C++ types. All the types I mentioned here can be copied by assignment or copy construction. Moreover, you can "cross-copy" from opne to another (and even from a built-in ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-program-to-copy-all-the-elements-of-one-array-to-another-array
C Program to Copy an Array to Another Array - GeeksforGeeks
July 23, 2025 - This method uses a loop to iterate through the array and assign each element to the corresponding index of another array. ... #include <stdio.h> void copyArr(int arr1[], int arr2[], int n) { for (int i = 0; i < n; i++) { // Copy each element ...
🌐
w3resource
w3resource.com › c-programming-exercises › array › c-array-exercise-4.php
C Program: Copy the elements of one array into another array - w3resource
September 27, 2025 - Write a C program to copy elements from one array to another without using a loop (using recursion).
🌐
Quora
cstdspace.quora.com › How-to-copy-one-array-to-another-using-the-C-programming-language
How to copy one array to another using the C programming language - C Programmers - Quora
Answer (1 of 8): The best way to do this is to first know what you are copying. Let’s call it an X. X could b a char, int, or a struct. Then we need to know how many elements. Let’s call that N. The correct call is to use memcpy as that is a library function that is very optimised.
🌐
Tutorial Gateway
tutorialgateway.org › c-program-to-copy-an-array-to-another
C Program to Copy an Array to another
January 25, 2025 - The final output of the C Program to Copy an Array to another is: b[5] = {10, 25, 45, 75, 95}
🌐
Youcademy
youcademy.org › copying-arrays-assign-list-to-another-list-c
Copying Arrays in C: How to Assign One List to Another List
The memcpy() function is a powerful and efficient way to copy arrays in C. It’s part of the <string.h> library and is designed to copy a block of memory from one location to another.
Find elsewhere
🌐
Reddit
reddit.com › r/c_programming › why in c arrays can be copied one element at a time using loop but entire array cannot be copied at one stroke
r/C_Programming on Reddit: Why in C arrays can be copied one element at a time using loop but entire array cannot be copied at one stroke
August 13, 2023 -

It will help to know explanation of the reason why in C arrays can be copied one element at a time using loop but entire array cannot be copied at one stroke.

So below seems correct way to copy array:

void blur(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE copyimage[height][width];
    for (int y = 0; y < height; y++)
        {
         for (int x = 0; x < width; x++)
               {
                copyimage[y][x] = image[y][x];
               }
        }

But not:

void blur(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE copyimage[height][width] = image[height][width];
}

Top answer
1 of 16
106
memcpy(dst,src,size);
2 of 16
52
u/fliguana has provided you with the standard approach for copying an entire array. But if you're wondering why arrays cannot be assigned like other kinds of values, you need to dig into the history of C. The B programming language, which preceded C, had the concept of "an array", but it did not have "an array type". In fact, it didn't really have types at all. Everything in B was an integer. In B an array was accessible only through what was essentially a pointer. For instance: auto a[10]; f(a[4]); would declare an array a of 10 integers, then call f on the fifth of those. But... as I said, everything in B is an integer, so even a was an integer. That integer would be a pointer to the array. And yes, this meant the array declaration was actually reserving space for both the array's contents and that pointer. So that meant: auto a[10]; f(a); would actually pass that pointer, the pointer to the first element of the array, to the f function. C wanted to have real arrays (in particular, so they could be meaningfully used inside structure types), but it always wanted to remain somewhat compatible with B — at least enough so that source code could be converted. So that's where C's automatic "arrays decay to pointers" behaviour came from. In B, arrays were pointers. In C, arrays get converted to pointers pretty much anywhere they're used. But what about array assignment? In B you could write: auto a[10]; auto b; b = a + 4; to simply set b to be a pointer to the fifth element of a. But that means you could also do: a = a + 4; to change the a pointer itself. That is, arrays could effectively be "rebased". But this kind of stuff really makes no sense in C. If you were to write: int a[10]; a = a + 5; what should happen? There isn't any pointer that can be updated by this operation. So in C, arrays simply aren't assignable. As a consequence, you cannot just write: int a[10], b[10]; a = b; to assign the contents of b to a. It wouldn't even make sense if arrays were assignable, since b would have decayed to a pointer anyway. To copy an array you have to do element-by-element assignment, or use a library function that effectively does the same thing for you.
🌐
TutorialsPoint
tutorialspoint.com › learn_c_by_examples › array_copy_program_in_c.htm
Program to copy array in C
procedure copy_array(A, B) SET index to 1 FOR EACH value in A DO B[index] = A[index] INCREMENT index END FOR end procedure · The implementation of the above derived pseudocode is as follows − · #include <stdio.h> int main() { int original[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; int copied[10]; int loop; for(loop = 0; loop < 10; loop++) { copied[loop] = original[loop]; } printf("original -> copied \n"); for(loop = 0; loop < 10; loop++) { printf(" - -\n", original[loop], copied[loop]); } return 0; }
🌐
Codeforwin
codeforwin.org › home › c program to copy all elements of one array to another
C program to copy all elements of one array to another - Codeforwin
July 20, 2025 - Now, to copy all elements from source to dest array, you just need to iterate through each element of source. Run a loop from 0 to size. The loop structure should look like for(i=0; i<size; i++). Inside loop assign current array element of source ...
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 110716-how-do-you-copy-one-array-c-another.html
How do you copy one array in C to another? - C Board
January 2, 2009 - You cannot write to an array, only to an individual cell in an array. So you must copy into same_age[0], into same_age[1], ..., ..., ....
🌐
TechieFreak
techiefreak.org › home › blogs › arrays › copy one array into another
How to Copy One Array into Another in C, C++, Java, Python
January 1, 2026 - source = [5, 10, 15, 20, 25] dest = [0] * len(source) for i in range(len(source)): dest[i] = source[i] print("Copied Array:", dest) ... using System; class Program { static void Main() { int[] source = {5, 10, 15, 20, 25}; int[] dest = new ...
🌐
Techcrashcourse
techcrashcourse.com › 2015 › 11 › c-program-to-copy-elements-from-one-array-to-another-array.html
C Program to Copy Elements From One Array to Another Array
#include <stdio.h> int main(){ int inputArray[100], copyArray[100], elementCount, counter; printf("Enter Number of Elements in Array\n"); scanf("%d", &elementCount); printf("Enter %d numbers \n", elementCount); for(counter = 0; counter < elementCount; counter++){ scanf("%d", &inputArray[counter]); } for(counter = 0; counter < elementCount; counter++){ copyArray[counter] = inputArray[counter]; } printf("Duplicate Array\n"); for(counter = 0; counter < elementCount; counter++){ printf("%d ", copyArray[counter]); } return 0; } Output · Enter Number of Elements in Array 5 Enter 5 numbers 5 3 8 1 -3 Duplicate Array 5 3 8 1 -3 Related Topics · Previous C Program to find Max and Min Element of an Array
🌐
Quora
quora.com › How-do-you-copy-a-const-array-into-another-array-C-programming
How to copy a const array into another array (C programming) - Quora
Answer (1 of 2): How do you copy a const array into another array (C programming)? Kind of depends on what you need. If both arrays are in a structure, just an assignment will do. Otherwise you are down to copying each element in a loop. See memmove and memcpy functions. There are some “not e...
🌐
Emory
cs.emory.edu › ~cheung › Courses › 170 › Syllabus › 09 › copy-array.html
Copying an array and changing the size of an array
Definition: copy of a variable · Copy of a variable = an independent variable that contains the exact value of the original variable
🌐
Coursecrux
coursecrux.com › posts › c-programs › pointers › 07-copy-array-to-another-pointers.html
Coursecrux | Copy one array to another using pointers
#include<stdio.h> #include<conio.h> #define MAX 50 void print_array(int arr[], int n); void main() { int arr1[MAX], arr2[MAX]; int n, i; int *ptr1, *ptr2; printf("Enter the size of the array\t:"); scanf("%d",&n); printf("\nEnter elements in the array\n"); for(i=0;i<n;i++) { scanf("%d",&arr1[i]); } ptr1 = arr1; //pointer ptr1 points to arr1[0] ptr2 = arr2; //pointer ptr2 points to arr2[0] printf("\nSource array before copying: "); print_array(arr1, n); printf("\nDestination array before copying: "); print_array(arr2, n); for(i=0;i<n;i++) { *ptr2 = *ptr1; *ptr1++; *ptr2++; } printf("\n\nSource array after copying: "); print_array(arr1, n); printf("\nDestination array after copying: "); print_array(arr2, n); getch(); } void print_array(int *arr, int n) { int i; for(i=0;i<n;i++) { printf("%d ",arr[i]); } }