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. ------


Relevant Pages

  • Re: How would you design Cs replacement?
    ... I would get rid of void. ... a member called size of type int. ... size of the array pointed at by v->dynamic is given by int size. ... If you pass an unsized pointer to a sized parameter, ...
  • 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: ...
  • 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. ...
  • (patch for Bash) regex case statement
    ... Following up on my previous patch for regex conditional tests, ... /* Return an array of strings; ... int dollarflag, zeropad, compareflag; ... SHELL_VAR *var; ...
  • Re: Strategy or Iterator?
    ... It would be possible to write a class that returns the variations ... GNU General Public License for more details. ... protected CombinatoricOperator(Telements, int r) { ... An integer array backing up the original one to keep track of the ...