Interview Questions and Answers :: Cisco
Home > Experience Archives > Cisco > Interview Question Set 1 > Discussion
6. What is difference in memcpy, strncpy.
Answer:
a) When memory block requires to be copied then memcpy is useful
when data in the form of string need to be copied then strncpy is useful because of the natural advantage of '\0' terminated string.
b) memcpy() can copy data with embedded null characters.
strncpy will copy the string to the maximum of either the number of characters given or the position of the first occurrence of null character, i.e '\0' , and reset will be filled with 0
Aman
8 Jul, 2018 12:39 PM
a) When memory block requires to be copied then memcpy is useful
when data in the form of string need to be copied then strncpy is useful because of the natural advantage of '\0' terminated string.
b) memcpy() can copy data with embedded null characters.
strncpy will copy the string to the maximum of either the number of characters given or the position of the first occurrence of null character, i.e '\0' , and reset will be filled with 0
when data in the form of string need to be copied then strncpy is useful because of the natural advantage of '\0' terminated string.
b) memcpy() can copy data with embedded null characters.
strncpy will copy the string to the maximum of either the number of characters given or the position of the first occurrence of null character, i.e '\0' , and reset will be filled with 0
Report Error
Report Error
Please Login First Click Here