본문 바로가기

42Seoul/libft36

ft_bzero bzero? #include void bzero(void *s, size_t n); Linux manpage description : The bzero() function erases the data in the n bytes of the memory starting at the location pointed to by s, by writing zeros (bytes containing '\0') to that area. 해석 및 부연설명 : memset과 똑같이 작동하지만 오로지 \0으로만 채울 수 있다. 다만 리턴값 없이 단순히 메모리를 0으로 초기화하는 용도인 듯 하다. deprecated(시대에 뒤쳐졌다는 의미) 되었으니 대신 memset을 사용하라고 한다. ex) int i = -1; char .. 2023. 2. 16.
ft_memmove memmove? #include void *memmove(void *dst, const void *src, size_t n); Linux manpage description : The memmove() function copies n bytes from memory area src to memory area dst. The memory areas may overlap: copying takes place as though the bytes in src are first copied into a temporary array that does not overlap src or dst, and the bytes are then copied from the temporary array to dst. 해석 및 부.. 2023. 2. 16.
ft_memcpy memcpy? #include void *memcpy(void *dst, const void *src, size_t n); Linux manpage description : The memcpy() function copies n bytes from memory area src to memory area dst. The memory areas must not overlap. Use memmove(3) if the memory areas do overlap. 해석 및 부연설명 : src에 저장되어있는 값을 n만큼 복사해 dst의 시작주소부터 붙여넣은 후 그 주소를 반환한다. 각 메모리가 overlap되어있어서는 안되며, 그럴 경우엔 memcpy 대신 memmove를 사용해야한다. ex) chardst[] =.. 2023. 2. 16.
ft_memset memset? #include void *memset(void *s, int c, size_t n); Linux manpage description : The memset() function fills the first n bytes of the memory area pointed to by s with the constant byte c. 해석 및 부연설명 : void형 포인터 s가 가리키고있는 메모리 주소의 처음 위치부터 n바이트만큼에 저장되어있는 값을 상수 c로 채우고, 원래 포인터 s의 값을 리턴한다. 이 때 s가 가리키는 주소는 같지만 주소에 저장되어있는 값은 바뀐다. ex) char str[] = "abcdefg"; memset(str, '!', 5 * sizeof(char)); printf(.. 2023. 2. 16.