To copy an array b[] into the array a[], one can use function memcpy as follows;
memcpy(a,b,sizeof(a)).
But memcpy simply copies bytes from one place to another.
My questions are:
1.How
memcpycopies elements of arrayb[]intoa[]by copying bytes?
2.Whysizeof(a)is supplied as arguments?
I am new to programming so, be gentle.
{void *data, size_t len}when allocating space fordata. Then you won't need to pass length of data to your ownmemcpy.sizeof(a)?sizeofcan be tricky. If, instead of a fixed-size array,ais a pointer (which will behave a lot like the fixed-size array variable in most other contexts), takingsizeof(a)can lead to "surprises".