Home > Author > >

" When Arrays Are Pointers The C standard has the following to say about the matter. Rule 1. An array name in an expression (in contrast with a declaration) is treated by the compiler as a pointer to the first element of the array1 (paraphrase, ANSI C Standard, paragraph 6.2.2.1). 1. OK nitpickers, there are a few minuscule exceptions that concern arrays treated as a whole. A reference to an array is not replaced by a pointer to the first element when: • the array appears as the operand of sizeof()—-obviously you want the size of the whole array here, not just a pointer to it. • the array’s address is taken with the & operator. • the array is a string or wide-string literal initializer. Rule 2. A subscript is always equivalent to an offset from a pointer (paraphrase, ANSI C Standard, paragraph 6.3.2.1). Rule 3. An array name in the declaration of a function parameter is treated by the compiler as a pointer to the first element of the array (paraphrase, ANSI C Standard, paragraph 6.7.1). "

, Expert C Programming: Deep C Secrets


Image for Quotes

 quote : When Arrays Are Pointers The C standard has the following to say about the matter. Rule 1. An array name in an expression (in contrast with a declaration) is treated by the compiler as a pointer to the first element of the array1 (paraphrase, ANSI C Standard, paragraph 6.2.2.1). 1. OK nitpickers, there are a few minuscule exceptions that concern arrays treated as a whole. A reference to an array is not replaced by a pointer to the first element when: • the array appears as the operand of sizeof()—-obviously you want the size of the whole array here, not just a pointer to it. • the array’s address is taken with the & operator. • the array is a string or wide-string literal initializer. Rule 2. A subscript is always equivalent to an offset from a pointer (paraphrase, ANSI C Standard, paragraph 6.3.2.1). Rule 3. An array name in the declaration of a function parameter is treated by the compiler as a pointer to the first element of the array (paraphrase, ANSI C Standard, paragraph 6.7.1).