PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > First address of a bidimensional array
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
First address of a bidimensional array

Réponse
 
LinkBack Outils de la discussion
Vieux 07/05/2008, 15h12   #1
nembo kid
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 07/05/2008, 15h24   #2
Tomás Ó hÉilidhe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: First address of a bidimensional array

On May 7, 3:12pm, nembo kid <u...@localhost.com> wrote:
> 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.
  Réponse avec citation
Vieux 07/05/2008, 17h36   #3
S S
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: First address of a bidimensional array

On May 7, 7:12 pm, nembo kid <u...@localhost.com> wrote:
> 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.
  Réponse avec citation
Vieux 07/05/2008, 18h04   #4
Default User
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: First address of a bidimensional array

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
  Réponse avec citation
Vieux 07/05/2008, 22h48   #5
Chris Torek
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: First address of a bidimensional array

In article <4821b7c6$0$35957$4fafbaef@reader2.news.tin.it>
nembo kid <user@localhost.com> wrote:
[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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h44.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11870 seconds with 13 queries