독립 실행 형 함수를 사용하여 배열에 할당 된 바이트 수를 얻으려고했지만 실패했습니다. 다음과 같이 내 코드는 다음과 같습니다배열을 함수 포인터로 전달하고 sizeof() 연산자 사용
#include <stdio.h>
void testing(char *source);
int main(){
char a[12] = "Hello World!";
//printf("%d",sizeof(a)); Prints 12. I want to get this value
testing(a); // Prints 4. I need to get 12 by using functions
return 0;
}
void testing(char *source){
printf("%d",sizeof(source));
}
내가 12대로 결과 싶어하지만 출력은 4
포인터를 사용하여'sizeof'에서 배열 크기를 가져올 수 없습니다. –
"나는 2 + 2가 5가 되길 바래."라고 말하는 것과 같습니다. 당신은 그것을 "간절히 원할"수는 있지만 일어날 수는 없습니다. 'sizeof'는 이것을하지 않습니다. – AnT
함수를'void testing (char (* source) [12])'로 변경하고 함수에서'sizeof * source'를 사용합니다. –