🧑🏻💻/C & C++(32)
-
[C] const
Const const는 왼쪽에 있는 것을 상수화시킨다. 만약에 없다면 오른쪽에 작용한다. char num = 0; const char * ptr1;// char에 적용(왼쪽에 아무것도 없기 때문) (값 변경 불가능) char * const ptr2;// *에 적용 (포인터 주소 변경 불가능) ptr1 = # ptr2 = #// const ptr2 상수화 (포인터 주소 변경 불가능) 컴파일 에러 *ptr1 = 10;// *ptr1 상수화 (값 변경 불가능) 컴파일 에러 *ptr2 = 20;// 런타임 에러(ptr2 가르키고있는곳 없음)
2022.09.15 -
[C] strjoin / strjoin.c / strjoin in c
Allocates (with malloc(3)) and returns a new string, which is the result of the concatenation of ’s1’ and ’s2’. char*ft_strjoin(char const *s1, char const *s2) { char*result; size_ttotal_length; if (!s1 || !s2) return (NULL); total_length = (ft_strlen(s1) + ft_strlen(s2) + 1); result = (char *)malloc(sizeof(char) * total_length); if (!result) return (NULL); ft_strlcpy(result, s1, total_length); ..
2022.09.14 -
[C] substr / substr.c / substr in c
char*ft_substr(char const *s, unsigned int start, size_t len) { char*result; size_tindex; if (!s) return (NULL); result = (char *)malloc(sizeof(char) * len + 1); if (!result) return (NULL); s += start; index = 0; while (s && len--) { *(result++) = *(s++); index++; } *result = '\0'; result -= index; return (result); }
2022.09.14 -
[C] memset / memset.c / memset in c
void*memset(void *b, int c, size_t len) { unsigned char*temp_b; temp_b = (unsigned char *)b; while (len--) *temp_b++ = (unsigned char)c; return (b); }
2022.07.25 -
[C] memmove / memmove.c / memmove in c
void*memmove(void *dst, const void *src, size_t len) { unsigned char*dest; unsigned char*source; dest = (unsigned char *)dst; source = (unsigned char *)src; if (dst src) { while (len--) *(dest + len) = *(source + len); } return (dst); } DESCRIPTION memmove함수는 비파괴적인 방식으로 사용되는 복사입니다. 변수명 설명 void *dst 설정할 메모리 주소 const void *src 복사할 메모리 ..
2022.07.25