Re: Pointer conversions



On Wed, 09 Jan 2008 14:54:46 +0200, Ioannis Vranos <john@xxxxxxx>
wrote:

CBFalconer wrote:
Ioannis Vranos wrote:

Correction:

array_2d[0] is an array of 5 ints.
array2d[0] is an array of 5 ints and it "behaves" (I do not know
the accurate technical term)as a pointer to array_2d[0][0], that is
*(array_2d[0]) is array_2d[0][0].

No. Don't drop the details. *(array_2d[0]) is a pointer to an
array of 5 ints. array_2d[0][0] is an int. Just one.


Actually my correction with addition of parentheses was not needed.

Given: int array_2d[10][5];

array_2d behaves like a pointer to an array of 5 ints.
array2d_[0] behaves like a pointer to array_2d[0][0];

Why the inconsistency in your description - one with a type and one
with an object?

The rule is very straight forward: "Except when it is the operand of
the sizeof operator or the unary & operator, or is a string literal
used to initialize an array, an expression that has type ??array of
type?? is converted to an expression with type ??pointer to type??
that points to the initial element of the array object..."

The expression
array_2d
is converted to a pointer to array_2d[0] which has type pointer to
array of 5 int and which is expressed syntactically as
&array_2d[0]
which has type
int (*)[5]

The expression
array_2d[0]
is converted to a pointer to array_2d[0][0] which has type pointer to
int and which is expressed syntactically as
&array_2d[0][0]
which has type
int *


Remove del for email
.



Relevant Pages

  • Re: Warning on assigning a function-returning-a-pointer-to-arrays
    ... This declares pfunc as a function taking no arguments and returning ... int x, y; ... Presumably pfuncwill return a pointer to a single int, ... or the first of a sequence of "array 5 of int"s. ...
    (comp.lang.c)
  • Re: Newbie
    ... to talk about the int value 3 and the int value 4, ... It also lets you talk about pointer ... C has a special rule for array objects. ... to printf() is: ...
    (comp.lang.c)
  • Re: union {unsigned char u[10]; ...}
    ... But character type is not a union. ... u.a is of type int. ... has to do so to make pointer equality work consistently). ... were a single-element array. ...
    (comp.lang.c)
  • Re: union {unsigned char u[10]; ...}
    ... But character type is not a union. ... u.a is of type int. ... has to do so to make pointer equality work consistently). ... were a single-element array. ...
    (comp.lang.c)
  • Re: How to pass a pointer to an unknown-size array?
    ... > I can pass a "pointer to a double" to a function that accepts ... > int func{ ... > Now I want to pass a pointer to an array of doubles, ...
    (comp.lang.c)