Because temp is not an array, it's a pointer and therefore sizeof(temp) has absolutely no relation to the array.

You want to change the memcpy to use sizeof(a). You will also want to give temp a sane value before copying to it, otherwise the program has undefined behavior.

Answer from Jon on Stack Overflow
๐ŸŒ
Arduino Forum
forum.arduino.cc โ€บ projects โ€บ programming
copy array content using memcpy() - Programming - Arduino Forum
January 8, 2015 - Hi all, I have defined three arrays: ... Now in my main loop I use: memcpy(arrPattern, arrRightOn, 10); arrPattern now contains {1,1,1,0,0,0,0,0,0,0} Next I use: memcpy(arrPattern, arrLeftOn, ......
Discussions

c - How to use memcpy to copy one array to another one? - Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Because I want to copy a large array,I heard that need to use memcpy. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Is there a way to memcpy an array data to another array data with specific location.
Prefer std::copy to the dangerous C library function memcpy (memcpy will only work for simple types such as integers): #include // Put at top std::copy(&x[0], &x[2], &y[3]); If you want some more advanced behavior, i.e. fill out zeros in y by copying the next element in x you have to implement it yourself with a loop and a counter. This is what programming is about: making algorithms for doing specific tasks. Unfortunately there is no standard my_specific_program() function for your project in the standard library. More on reddit.com
๐ŸŒ r/cpp_questions
18
3
September 4, 2022
c - memcpy(), what should the value of the size parameter be? - Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I want to copy an int array to another int array. They use the same define for length so they'll always be of the same length. What are the pros/cons of the following two alternatives of the size parameter to memcpy... 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
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ c_standard_library โ€บ c_function_memcpy.htm
C library - memcpy() function
Following is the syntax of the C library memcpy() function โˆ’ ยท void *memcpy(void *dest_str, const void * src_str, size_t n) ... dest_str โˆ’ This parameter define a pointer to the destination array where the content is to be copied.
๐ŸŒ
Cplusplus
cplusplus.com โ€บ reference โ€บ cstring โ€บ memcpy
memcpy
The function does not check for any terminating null character in source - it always copies exactly num bytes. To avoid overflows, the size of the arrays pointed to by both the destination and source parameters, shall be at least num bytes, and should not overlap (for overlapping memory blocks, ...
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ c-copying-data-using-the-memcpy-function-in-c
C: Copying data using the memcpy() function in C
In C, the memcpy() function copies n number of characters from one block of memory to another. ... Destination: Pointer to the destination array where data will be copied.
๐ŸŒ
GNU
gnu.org โ€บ software โ€บ libc โ€บ manual โ€บ html_node โ€บ Copying-Strings-and-Arrays.html
The GNU C Library - GNU Project - Free Software Foundation (FSF)
This glibc manual version 2.43 (latest) is available in the following formats: ยท The manual is available for the following releases of glibc:
๐ŸŒ
TechOnTheNet
techonthenet.com โ€บ c_language โ€บ standard_library_functions โ€บ string_h โ€บ memcpy.php
C Language: memcpy function (Copy Memory Block)
The number of characters to copy. The memcpy function returns s1. In the C Language, the required header for the memcpy function is: ... /* Example using memcpy by TechOnTheNet.com */ #include <stdio.h> #include <string.h> int main(int argc, const char * argv[]) { /* Create a place to store our results */ int result; /* Create two arrays to hold our data */ char original[50]; char newcopy[50]; /* Copy a string into the original array */ strcpy(original, "C memcpy at TechOnTheNet.com"); /* Copy the first 24 characters of the original array into the newcopy array */ result = memcpy(newcopy, orig
๐ŸŒ
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 - #include <stdio.h> #include <string.h> ... // Use memcpy to copy arr1 to arr2 memcpy(arr2, arr1, n * sizeof(arr1[0])); for (int i = 0; i < n; i++) printf("%d ", arr2[i]); return 0; } ... Explanation: The memcpy() function copied ...
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.
๐ŸŒ
Youcademy
youcademy.org โ€บ copying-arrays-assign-list-to-another-list-c
Copying Arrays in C: How to Assign One List to Another List
You need a true independent copy of the array data. In most cases, itโ€™s safer and more predictable to use deep copy methods like memcpy() or element-by-element copying to create truly independent array copies.
๐ŸŒ
GNU
gnu.org โ€บ software โ€บ libc โ€บ manual โ€บ 2.29 โ€บ html_node โ€บ Copying-Strings-and-Arrays.html
Copying Strings and Arrays (The GNU C Library)
The behavior of this function is undefined if the two arrays wto and wfrom overlap; use wmemmove instead if overlapping is possible. The following is a possible implementation of wmemcpy but there are more optimizations possible. wchar_t * wmemcpy (wchar_t *restrict wto, const wchar_t *restrict wfrom, size_t size) { return (wchar_t *) memcpy (wto, wfrom, size * sizeof (wchar_t)); } The value returned by wmemcpy is the value of wto. This function was introduced in Amendment 1 to ISO C90.
๐ŸŒ
Sternum IoT
sternumiot.com โ€บ home โ€บ memcpy c function โ€“ syntax, examples, and security best practices
memcpy C Function | Syntax, Examples & Security Best Practices | Sternum IoT
January 30, 2024 - The memcpy() function copies the contents of a source buffer to a destination buffer, starting from the memory location pointed to by src, and continuing for n bytes. The areas of memory should not overlap, and the behavior is undefined if they do.
๐ŸŒ
W3Resource
w3resource.com โ€บ c-programming โ€บ string โ€บ c-memcpy.php
C memcpy() function
2 weeks ago - The program defines a source array of integers and a destination array. memcpy() copies the entire source array into the destination array.
๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ c-programming โ€บ 134799-memcpy-part-array-specific-position-different-array.html
memcpy - part of array to specific position in different array
February 17, 2011 - #define MSG_LENGTH 4096 static wchar_t *wcMessageIn; static wchar_t *wcMessageOut; int main(int argc, char *argv[]) { wcMessageIn = (wchar_t *)malloc(MSG_LENGTH * sizeof(wchar_t)); wcMessageOut = (wchar_t *)malloc(MSG_LENGTH * sizeof(wchar_t)); /* receive message and convert it to wcMessageIn using mbstowcs */ /* lMsgWCharLen = mbstowcs(wcMessageIn, cMessage, MSG_LENGTH); */ /* copy 4th character on input to 1st character on output - THIS WORKS*/ wcMessageOut[0] = wcMessageIn[3]; /* append 3th to 5th character on input to output - THIS DOES NOT WORK */ memcpy(wcMessageOut + 1*sizeof(wchar_t), wcMessageIn + 2*sizeof(wchar_t), 3*sizeof(wchar_t)); /* do some cleanup here */ } Can you please help me with the memcpy?
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ memcpy in c
memcpy() in C
April 14, 2024 - In the C Programming Language, the memcpy function copies n characters from the object pointed to by s2 into the object pointed to by s1. It returns a pointer to the destination.