473,586 Members | 2,702 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 1544
/* 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
6255
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 finished. My previous solution to this was to filter by query or SQL for the observations for a particular set of criteria, then go through the...
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 4 4 4 4 0 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
1
1011
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 BeanSoftware.Components.CommonCrypt() I don't have visual studio, so I put the line in with notepad. But when I loaded the asp.net page in my browser, I got the following error...
5
3798
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 matrix, then free the original matrix and have the pointer of the original matrix point towards the new matrix. Any suggestions for making this...
6
3964
by: kilter | last post by:
Anyone know of a routine that will return the number of rows and columns in a matrix?
7
14977
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 code I have (I am using Python): def generate (rows, cols): # This just prints the coordinates and the number that goes in it, It also prints the...
2
1284
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 have to use these matrices in furthur calculations.How can I proceed for this problem? Here array defining should also be dynamic and I am also facing...
4
2935
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 Matrix as an input array and numbers of the matrix rows and columns (Similar to SIZE( ) function in MATLAB) as outputs. Best regards, BASHAR AHMAD
5
12788
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
8200
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8215
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3836
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.