A Piece of Code
Showing posts with label
memcpy
.
Show all posts
Showing posts with label
memcpy
.
Show all posts
Friday, January 25, 2013
malloc memcpy
1 struct Test {
2 char * ptr;
3 };
4 void shallow_copy(Test & src, Test & dest) {
5 dest.ptr = src.ptr;
6 }
7 void deep_copy(Test & src, Test & dest) {
8 dest.ptr = malloc(strlen(src.ptr) + 1);
9 memcpy(dest.ptr, src.ptr);
10 }
Older Posts
Home
Subscribe to:
Posts (Atom)