473,509 Members | 3,095 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Omitting rows numbers of a matrix

Why I can omit numbers of rows, when I define
a two-dimensions array i.e. :

double table [] [100];
thanks

Nov 14 '05 #1
1 1526
/* 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.

--
Er*********@sun.com

Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6250
by: Howard William | last post by:
Help. I am a bit flummoxed by the problem of how to transpose "normalized" (in the database sense) data records into columns of for a data entry form, and then back again when the user is...
4
320
by: rburdette | last post by:
I need to do a sum of rows and sum of columns in Visual Basic. Is there another way to do it other than the one I have below? 5 7 3 9 12 4 8 9 13 4 0 -`1 -7 13 8...
1
1005
by: BLACKDOG157 | last post by:
I bought a dll, put it in my website's BIN directory, and then put a line in my asp.net page as follows: Dim MyCrypt As BeanSoftware.Components.CommonCrypt = New...
5
3787
by: A | last post by:
I am wondering if there's an efficient way of deleting rows or columns of a gsl_matrix? The only way I can think of is copying individual elements or may be rows, columns or sumatrices to a new...
6
3958
by: kilter | last post by:
Anyone know of a routine that will return the number of rows and columns in a matrix?
7
14964
by: lethek39 | last post by:
Hey I have been trying to figure out how to sum rows and columns in a matrix square. I also have been trying to get the program to list the numbers of the diagonal in the matrix. So far this is the...
2
1278
by: debiasri | last post by:
I have to devide a matrix in variable no of matrices with each having variable no of rows. Like I have to devide a matrix with dim.9X19 into say 4 matrices with row nos 1,6,6,6 respectively, and I...
4
2931
by: hefty1985 | last post by:
Dear all, I hope you can help. Is any one aware of a function that would return the number of Rows and Columns of a 2-D array in C ( Matrix)? Or, how to go about writting a function with the...
5
12780
by: 15153681 | last post by:
I'm still new to python, so I would like to know how do I get random numbers in my matrix; more specific, what is the commands for getting a random matrix. THANX for the help guys
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.