Today, there was a problem when I wanted to implement memcpy while learning memcpy (vs2019 I used)

CSDN Q & A 2022-01-15 02:35:59
The phenomenon and background of the problem

++ Lvalue required

void* my_memcpy(void* dest,const void* src,size_t num){ void* ret = dest; assert(dest!=NULL); assert(num!=NULL); while (num--) { *(char*)dest = *(char*)src; ++(char*)dest; ++(char*)src; } return ret;}struct s{ char name[20]; int age;};int main(){ struct s a3[20]= { {
" Zhang San ", 20},{
" Li Si ",21} }; struct s a4[10]= {
"0"}; my_memcpy(a1, a2, sizeof(a3)); printf("%s", a4->name); return 0;}
Operation results and error reporting contents
My solution ideas and tried methods

I created two new character arrays void The value of the pointer is placed inside to ++, But the output is ?

What I want to achieve

Similar articles