Re: arrays are not tables?
- From: Lew Pitcher <lpitcher@xxxxxxxxxxxx>
- Date: Wed, 11 Mar 2009 16:12:34 -0400
On March 11, 2009 15:34, in comp.os.linux.development.apps, Antonio Macchi
(antonio_macchi@xxxxxxxx) wrote:
[snip]
this is the head of the function of the exampleIn the context of the binsearch function declaration, v is an array of int.
int binsearch(int x, int v[], int n)
the "table" is "int v[]"
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
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
.
- References:
- arrays are not tables?
- From: Antonio Macchi
- arrays are not tables?
- Prev by Date: Re: arrays are not tables?
- Next by Date: Re: arrays are not tables?
- Previous by thread: Re: arrays are not tables?
- Next by thread: Re: arrays are not tables?
- Index(es):
Relevant Pages
|