Hello, I am new to C++.
I know the use of function memcpy().
but what is the difference between using memcpy(&str1, &str2, sizeof(str2)) and str1 = str2 ?
Hello, I am new to C++.
I know the use of function memcpy().
but what is the difference between using memcpy(&str1, &str2, sizeof(str2)) and str1 = str2 ?
memcpy will copy the contents of an address for n bytes. str1 = str2 will assign the address str2 to str1 (assuming they're pointers).
is memcpy() slower if I want to copy a exact variable ?Originally posted by Enmeduranki
memcpy will copy the contents of an address for n bytes. str1 = str2 will assign the address str2 to str1 (assuming they're pointers).
>is memcpy() slower if I want to copy a exact variable ?
You're not copying an exact variable by assigning one pointer to another. You're copying a pointer.
how if I using * before a pointer ?Originally posted by Enmeduranki
>is memcpy() slower if I want to copy a exact variable ?
You're not copying an exact variable by assigning one pointer to another. You're copying a pointer.
If you're only copying sizeof(one primitive) then yes.
you mean memcpy() is slower ?Originally posted by Enmeduranki
If you're only copying sizeof(one primitive) then yes.
Almost definitely, but it'll be up to the implementation.
Thanks !