prev up next   top/contents search

comp.lang.c FAQ list · Question 6.12

Q: Since array references decay into pointers, if arr is an array, what's the difference between arr and &arr?


A: The type.

In Standard C, &arr yields a pointer, of type pointer-to-array-of-T, to the entire array. (In pre-ANSI C, the & in &arr generally elicited a warning, and was generally ignored.) Under all C compilers, a simple reference (without an explicit &) to an array yields a pointer, of type pointer-to-T, to the array's first element.

For a simple array

	int a[10];
a reference to a has type ``pointer to int,'' and &a is ``pointer to array of 10 ints.'' For a two-dimensional array like
	int array[NROWS][NCOLUMNS];
a reference to array has type ``pointer to array of NCOLUMNS ints,'' while &array has type ``pointer to array of NROWS arrays of NCOLUMNS ints.''

See also questions 6.3, 6.13, and 6.18.

References: ISO Sec. 6.2.2.1, Sec. 6.3.3.2
Rationale Sec. 3.3.3.2
H&S Sec. 7.5.6 p. 198


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

Hosted by Eskimo North