Thursday, April 27, 2017

memcpy vs strcpy

The functions which begins with "mem" prefix also operate on characters but, they do not use the null terminator convention.

This is the reason they will always need the size of characters to operate on.

For example, when using memcpy it requires size as well, though, strcpy only needs dest and src pointers. It can automatically detect end of string using null character.

void *memcpy(void *dest, const void *src, size_t n);
 
char *strcpy(char *dest, const char *src); 

Monday, April 24, 2017

What is Smart Pointer

Smart pointer is a class which wraps raw C++ pointers with some additional functionality, e.g. automatic memory de-allocation, reference counting etc.

Smart pointers should be preferred over raw pointers because it could help in overcoming some limitation of raw pointers such as memory leak, dangling pointers etc.