prev up next   top/contents search

comp.lang.c FAQ list · Question 6.21

Q: Why doesn't sizeof properly report the size of an array when the array is a parameter to a function? I have a test routine

	f(char a[10])
		int i = sizeof(a);
		printf("%d\n", i);
and it prints 4, not 10.

A: The compiler pretends that the array parameter was declared as a pointer (that is, in the example, as char *a; see question 6.4), and sizeof reports the size of the pointer. See also questions 1.24 and 7.28.

References: H&S Sec. 7.5.2 p. 195

prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North