Re: arrays are not tables?

On March 11, 2009 15:34, in comp.os.linux.development.apps, Antonio Macchi
(antonio_macchi@xxxxxxxx) wrote:
this is the head of the function of the example

int binsearch(int x, int v[], int n)

the "table" is "int v[]"
In the context of the binsearch function declaration, v is an array of int.

In reality, v is a pointer to (one or more) int, because of the way that
C "decays" array references into pointers. So, as far as the binsearch
declaration goes, it /could/ have been written as
int binsearch(int x, int *v, int n)
and been just as correct.

If you read your K&R, you'll note a passage that explains that the language
treats v[i] exactly as if it had been written as *(v+i). Array references
are internally rewritten as pointer expressions.

Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576 | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------