sizeof랑 strlen이랑;;;;;;;;; 마니 햇갈려요
이름이없다고
2023.04.01
sizeof랑 strlen이랑;;;;;;;;; 잘;;;;;;;;;ㅠㅠ
sizeof랑 strlen이랑 배열 들어갔을때랑 포인터 들어갔을때랑 잘;;; 모르겠어요 ㅠ
특히 2번요.... 결과가 15 14 4 14 ㄴㅏ오는데 뒤에 두개 값이 잘;;;;;ㅠㅠ
질문 내용 :
1.
#includestdio.h
#includestring.h
int f(char a[100])
{
return sizeof(a);
}
int main()
{
char a[100];
printf(%d\n, sizeof(a)+f(a));
}
2.
#include stdio.h
#include string.hvoid main()
{
char strBuf[15] = KIM SEOUNG MIN;
char *ptrBuf = KIM SEOUNG MIN;printf(%d %d %d %d\n, sizeof(strBuf), strlen(strBuf), sizeof(ptrBuf), strlen(ptrBuf));
}
-
목화
조금씩 이해 되려고 하네요 ㅎㅎㅎ
-
다이
strlen은 문자열의 길이를 구하는 함수입니다. 문자열의 끝에는 반드시 0이 들어갑니다, 따라서 strlen 함수는 최초로 발견되는 0까지의 크기가 됩니다.
sizeof(배열)은 배열의 전체크기가 됩니다.
sizeof(포인터)는 포인터의 크기이므로 항상 4가 됩니다.