memcpy

홍민주·2021년 5월 14일
0

memcpy

- 함수 설명

The memcpy() function copies n bytes from memory area src to memory area dst.
메모리 영역이 겹치면 안됨 -> 겹칠 경우는 memmove 사용

- 매개변수

변수명설명
dst복사되는 메모리의 첫번째 주소
src복사할 메모리의 첫번째 주소
n복사할 길이 (byte 단위)

- 반환값

성공 : the original value of dst.
실패 : NULL

- 코드

void	*memcpy(void *restrict dst, const void *restrict src, size_t n)
{
	unsigned char	*dst_ptr;
	unsigned char	*src_ptr;
	size_t			i;

	i = 0;
	dst_ptr = (unsigned char *)dst;
	src_ptr = (unsigned char *)src;
	if (dst_ptr == NULL && src_ptr == NULL)
		return (NULL);
	while (i++ < n)
		*dst_ptr++ = *src_ptr++;
	return (dst);
}
profile
백엔드 주니어 개발자 입니다~

0개의 댓글