Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Omitting rows numbers of a matrix

Reply
Thread Tools

Omitting rows numbers of a matrix

 
 
/* frank */
Guest
Posts: n/a
 
      06-25-2004
Why I can omit numbers of rows, when I define
a two-dimensions array i.e. :

double table [] [100];


thanks

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      06-25-2004
/* frank */ wrote:
> Why I can omit numbers of rows, when I define
> a two-dimensions array i.e. :
>
> double table [] [100];


First, let's simplify to a one-dimensional array. There
are three principal contexts where you can omit the element
count:

- When the array is defined and an initializer is
provided, the compiler deduces the array size from
the number of initializer values:

double vector[] = { 1, 2, 3, 27 };

has the same effect as

double vector[4] = { 1, 2, 3, 27 };

- When you write a declaration of an array that "lives
elsewhere," you can omit the array size:

extern double vector[];

gives the compiler all the information it needs to
generate code to access the elements of this array;
it does not need to know how many elements exist.

- When you write an array declaration in a function
parameter list, it is automatically transformed into
a declaration of a pointer to the array's first element.
Such a pointer carries no information about the number
of elements in the array, and since the count would be
"thrown away" anyhow, you needn't provide it. These
three function definitions have the same meaning:

int f(double p[4]) { ... }
int f(double p[]) { ... }
int f(double *p) { ... }

If any of this is confusing, I suggest you review Section 6
in the comp.lang.c Frequently Asked Questions (FAQ) list

http://www.eskimo.com/~scs/C-faq/s6.html

All the above concerns one-dimensional arrays, but your
original question was about two-dimensional arrays. Here's
the connection: C doesn't actually support multi-dimensional
arrays at all! When we speak of a "two-dimensional array" in
C, what we actually mean is a one-dimensional array whose
individual elements are themselves one-dimensional arrays.
We can show this more explicitly with a typedef:

typedef double Row[100];
Row table[];

The second line says "`table' is an array containing an unknown
number of `Row' elements." The first line says "A `Row' is an
array of 100 `double' elements." Together, the two lines say
exactly the same thing as `double table[][100];'.

You may wonder why we can't write `double table[][];' for
an array of unknown size whose elements are arrays of unknown
size, or why we can't write `typedef double Row[];' in the
explicit reformulation. The reason is that the compiler needs
complete information about the type of an array's elements, even
though it doesn't (usually) need to know exactly how many elements
there are. And the problem in the "two-dimensional" case is that
"complete information" about an array's type includes the element
count. Think about it: The compiler needs to know how many bytes
to skip over when going from `table[0]' to `table[1]', which means
it needs to know the `sizeof' the element -- and if the element is
itself an array, that means the compiler needs to know how many
elements the sub-array contains.

The upshot is that only the "leftmost" dimension of a "multi-
dimensional" array can be left unspecified (in the cases described
above), but the other dimensions must be specified fully.

--


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
asp.net page won't work with dll, what am I omitting? BLACKDOG157@LYCOS.COM ASP .Net 1 12-20-2005 03:13 PM
Omitting duplicates (In RSS feeds) gaikokujinkyofusho@gmail.com XML 0 01-17-2005 06:58 AM
Omitting the .ASPX Extension RC ASP .Net 5 11-29-2004 07:18 AM
log4j - Omitting stack trace with ConsoleAppender Christian Ashby Java 5 08-24-2004 10:07 PM
omitting config values Eric Tishkoff ASP .Net 2 07-02-2003 05:18 AM



Advertisments