당신은 값이 아닌 사용 일어나는 이해하는 디버거를 통해이를 실행하기
printf("char is %c",*arr);
시도를 주소를 인쇄하고 무엇을 당신이 생각처럼 일이, 당신은 관찰 무엇을해야 진짜 질문을하시기 바랍니다 대신. 이렇게하면 아마도 대부분의 질문에 스스로 대답하게 될 것입니다.
그런데 한 번 인쇄 할 때 arr은 지역 변수이고 sizeof는 원래 배열의 크기를 알 수 없으므로 인쇄 크기는 4입니다. 아래 코드는이 동작을 보여 주며 그 차이점 sizeof에 관해서는 배열과 포인터 사이. 당신이하려고하면
편집 :
#include <stdio.h>
void print(char *);
int main(int argc, char ** argv)
{
char temp = 'r';
char temp2[] = {'a','b'};
char temp3[] = {'r'};
print(&temp);
print(temp2);
print(temp3);
printf("sizeof temp is %d\n",sizeof(&temp));
printf("sizeof temp2 is %d\n", sizeof(temp2));
printf("sizeof temp3 is %d\n",sizeof(temp3));
return 0;
}
void print(char * arr)
{
printf("size of arr is %d\n", sizeof(arr));
printf("arr contains %c\n", *arr);
}
당신은 다니엘의 코멘트에 실제로 단지 추측보다는, 테스트 뭔가에 코드 덕분에 변화를 얻을 :
size of arr is 4
arr contains r
size of arr is 4
arr contains a
size of arr is 4
arr contains r
sizeof temp is 4
sizeof temp2 is 2
sizeof temp3 is 1
그리고 무엇을 기대합니까? –
-1 : 귀하의 질문은 무엇입니까? – hillu
또한!의 연속 된 시리즈로 질문을 게시하지 마십시오. –