473,383 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

First address of a bidimensional array

I have the following bidimensional array

int a [100][100];

Why the first address of this array is only:

& (mat[0][0])

and not also:

mat

like any other array?

Thanks in advance
Jun 27 '08 #1
4 1623
On May 7, 3:12*pm, nembo kid <u...@localhost.comwrote:
I have the following bidimensional array

int a [100][100];

You're right that this is a bi-dimensional array, however the C
language sees it and treats it as an array of arrays. It's the same as
doing the following:

typedef int HundredInts[100];

HundredInts a[100];

Why the first address of this array is only:

& (mat[0][0])

and not also:

mat

You have an array consisting of 100 elements, each of which is a
"HundredInts". The first element of this array is a HundredInt. You
get the first element by doing the following:

a[0];

The type of a[0] is HundredInts, so a pointer to the first element is
going to be a "HundredInt *", or "int (*)[100]".

Basically it all boils down to the fact that a multi-dimensional
arrays is implemented as an array of arrays.
Jun 27 '08 #2
S S
On May 7, 7:12 pm, nembo kid <u...@localhost.comwrote:
I have the following bidimensional array

int a [100][100];

Why the first address of this array is only:

& (mat[0][0])

and not also:

mat

like any other array?

Thanks in advance
"mat" contains the address of the first element of your 2D array.
"*mat" is the first address of your array.
"**mat" is the first element of your 2D array.
Jun 27 '08 #3
nembo kid wrote:
I have the following bidimensional array

int a [100][100];
I assume you mean "mat" here, to be consistent with what follows.
Why the first address of this array is only:

& (mat[0][0])
It's not. That's the first element of the first element.
and not also:

mat
That gives you the address of the first element. The first element is
an array of int of size 100.
like any other array?
It is like any other array. You just don't understand how it works. The
name of the array in most circumstances is converted to a pointer to
the first element. So "mat" is of type "pointer to array 100 of int",
and points to the beginning of mat[0].

I recommend reading over the FAQ entries on pointers and arrays.


Brian
Jun 27 '08 #4
In article <48***********************@reader2.news.tin.it>
nembo kid <us**@localhost.comwrote:
[given]
>int a[100][100];
Why the first address of this array is only:
&(mat[0][0])
[vs mat, mat+0, or &mat[0]; but consider also &mat!]

See the diagram at <http://web.torek.net/torek/c/pa.html>: there
are multiple "first address"-es, differing in type, and hence in
the "size of the circles".

Here is the next point to ponder: Are they all "the same" address?
Maybe they are, maybe they are not. Is 3.14159265 the same number
as 3? How about 3.00000 vs 3? What happens if you printf() the
result of the following four comparisons?

(int)3.14159265 == 3
(double)3 == 3.14159265
(int)3.0 == 3
(double)3 == 3.0

Based on what you get if you do printf() those, is it perhaps the
case that 3.0 is "more equal to 3" than 3.14159265?

(We can only compare things for equality after we convert them to
some common type, and the conversion itself may -- or may not --
change "something important". When we convert a double to an int,
we chop off the fractional part. Is it important? Maybe, but
maybe not: it all depends on what we *meant* with the original
double.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out) http://web.torek.net/torek/index.html
Jun 27 '08 #5

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

Similar topics

8
by: ehames | last post by:
Hi guys, As far as I know, for any type T, and positive integer N, if I have an array declared as: T array; then, &array and array are the same element. Is there any reason why a
16
by: Martin Joergensen | last post by:
Hi, I wanted to try something which I think is a very good exercise... I read in data from the keyboard and store them in a structure. There's a pointer called "data_pointer" which I use to...
11
by: Pedro Pinto | last post by:
Hi there! I'm having a problem in my program. i've created this structure: typedef struct tabela tabela; struct tabela { char nome; int nColunas; int nLinhas; char nomeColunas;
4
by: Anna | last post by:
Hi, I have the following MySQL table: inner_id data1 data2 data3 ->0 g sd ds 1 a n ...
8
by: Santiago Romero | last post by:
Hi :) First of all, I must apologize for my poor english :) I'm starting with python and pygame and for testing (and learning) purposes I wrote an small "Map Editor" for a small game project...
3
by: SM | last post by:
Hello, I have an array that holds images path of cd covers. The array looks like this: $cd = array( 589=>'sylver.jpg', 782=>'bigone.jpg', 158=>'dime.jpg' );
7
by: Szabolcs Borsanyi | last post by:
I know that this topic has been discussed a lot, still I'd appreciate a clear cut (and correct) answer: I pass a multidimensional array to a function, which is defined as int f(int a) { int...
4
by: mab464 | last post by:
I have this code on my WAMP server running on my XP machine if ( isset( $_POST ) ) { for($i=0; $i<count($_POST);$i++) { if ($ans != NULL ) $ans .= ", " . $_POST ; // Not the first...
1
by: lumumba401 | last post by:
Hello everybody, i am asking about how to define a bidimensional dynamic array as a global variable to use as incoming variable in a function Let us see , for example in a part of a programm...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.