Question:
how would you use the functions memcpy(),memset(),memmove()?
Answer:
Source: CoolInterview.com
memcpy() function copies n bytes from the object pointed to by s2 into the object pointed to by s1. If copying takes place between objects that overlap, the behavior is undefined. memmove() function shall copy n bytes from the object pointed to by s2 into the object pointed to by s1. Copying takes place as if the n bytes from the object pointed to by s2 are first copied into a temporary array of n bytes that does not overlap the objects pointed to by s1 and s2, and then the n bytes from the temporary array are copied into the object pointed to by s1. memset() function copies c (converted to an unsigned char) into each of the first n bytes of the object pointed to by s. SYNTAX: void *memcpy(void *s1, const void *s2, size_t n); void *memmove(void *s1, const void *s2, size_t n); void *memset(void *s, int c, size_t n); Source: CoolInterview.com
Answered by: Kishore | Date: 6/16/2008
| Contact Kishore
memset(str, '*', 50); // sets the first 50 characters of the string str to *. memcpy(str2, str1, 50); // copies the first 50 characters of str1 to str2. Source: CoolInterview.com
Answered by: clara phillips | Date: 6/24/2010
| Contact clara phillips
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|