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
🌐
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 - The third for loop then copies the elements of arr1 into a second array arr2 by iterating over each element of arr1 and assigning it to the corresponding index of arr2. The next two printf statements then print out the contents of the first array arr1 and the second array arr2 respectively, using separate for loops to iterate over the elements of each array and print them out using printf. ... Write a C program to copy elements from one array to another without using a loop (using recursion).
🌐
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
Discussions

How to copy a char array in C? - Stack Overflow
In C, I have two char arrays: char array1[18] = "abcdefg"; char array2[18]; How to copy the value of array1 to array2 ? Can I just do this: array2 = array1? More on stackoverflow.com
🌐 stackoverflow.com
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
c - Fast way to copy an array - Stack Overflow
So at the end of each iteration that I'm doing, I want to make my array be equal to my new array (which I have called array_new). I want every element of array to take the same value as is in array... More on stackoverflow.com
🌐 stackoverflow.com
Is there a function to copy an array in C/C++? - Stack Overflow
I know that Java has a function System.arraycopy(); to copy an array. I was wondering if there is a function in C or C++ to copy an array. I was only able to find implementations to copy an array by More on stackoverflow.com
🌐 stackoverflow.com
🌐
Tutorial Gateway
tutorialgateway.org › c-program-to-copy-an-array-to-another
C Program to Copy an Array to another
January 25, 2025 - This C program allows the user to enter the size of an Array and then elements of an array. Using For Loop, we are going to copy each element to the second array.
🌐
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 ...
🌐
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.
Find elsewhere
🌐
Youcademy
youcademy.org › copying-arrays-assign-list-to-another-list-c
Copying Arrays in C: How to Assign One List to Another List
Space complexity: O(1) for the copying process itself (excluding the space for the destination array). While strcpy() is convenient for string copying, it’s generally recommended to use strncpy() or other safer alternatives to prevent buffer overflow issues. The assignment operator (=) in C can be used to create a shallow copy of an array.
🌐
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.
🌐
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 !
🌐
ProCoding
procoding.org › c-program-to-copy-one-array-to-another-using-pointers
C program to copy one array to another using pointers | ProCoding
March 9, 2024 - Pointers play a vital role in array manipulation, enabling efficient memory management and dynamic allocation. To copy one array to another in C, we leverage pointers to iterate through the elements of both arrays and perform the copy operation.
🌐
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], ..., ..., ....
🌐
Emory
cs.emory.edu › ~cheung › Courses › 170 › Syllabus › 09 › copy-array.html
Copying an array and changing the size of an array
copy the value of variable a (5000 in the example) into the · variable b. Result: Notice that the · array elements can · now be accessed through the · reference variable b: The · names of the array elements accessed through the · reference variable b are: In other words, the ·
🌐
LabEx
labex.io › labs › cpp-copy-array-contents-in-c-298165
Copy Array Contents in C
Learn how to efficiently copy array contents and compare values in C programming.
🌐
Quora
quora.com › How-do-I-copy-an-array-in-C
How to copy an array in C++ - Quora
Answer (1 of 8): Re “How do I copy an array in C++?”: Don’t use arrays in C++; they’re left-over from C and are obsolete in C++. Use std::vector instead. (Look it up in any C++ book or just google it.) If you are in a class with an instructor who is telling you to use arrays in C++, ...
🌐
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...
🌐
Codecademy
codecademy.com › docs › c# › arrays › .copy()
C# (C Sharp) | Arrays | .Copy() | Codecademy
March 20, 2023 - The .Copy() method in C# copies a range of elements from one array to another array.
🌐
The Coding Forums
thecodingforums.com › archive › archive › c programming
Copy array of structs in one go | C Programming | Coding Forums
April 16, 2014 - Click to expand... Try: memcpy(dest,source,sizeof(dest)); Note this will copy any padding too. ... I want to copy an array of structs (fixed size array and struct).