home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!usc!elroy.jpl.nasa.gov!ncar!noao!asuvax!ennews!envmsa.eas.asu.edu!ptran
- From: ptran@envmsa.eas.asu.edu (Phi-Long Tran)
- Subject: Re: pointer to multi D array. How?
- Message-ID: <28AUG199208202210@envmsa.eas.asu.edu>
- News-Software: VAX/VMS VNEWS 1.4-b1
- Sender: news@ennews.eas.asu.edu (USENET News System)
- Organization: Arizona State University, Tempe, AZ
- References: <1992Aug26.050053.114348@zeus.calpoly.edu> <RICHARD.92Aug27181915@CLYDE.ttt.kth.se>
- Date: Fri, 28 Aug 1992 15:20:00 GMT
- Lines: 27
-
- In article <RICHARD.92Aug27181915@CLYDE.ttt.kth.se>,
- RICHARD@CLYDE.ttt.kth.se writes...
- >In article <1992Aug26.050053.114348@zeus.calpoly.edu>
- clin@zeus.calpoly.edu (Chihtsung Jeffrey Lin) writes:
-
- >> ... How do you declare a pointer to a multi-dimensional array? [H]ere
- >> is what I did.
- >> int A[5][5]:={1,2,3,......}, **x;
-
- > Make that:
- > int A[5][5]={1,2,3,.....}, *x;
-
- Why not make an actual pointer to an array? It may make references
- easier to code. For example, a pointer to the array A declared above would
- be, "int (*ptrA)[5][5]". Then we could reference array A with ptrA as:
-
- ptrA = &A; /* Assign ptrA the address of array A. */
- (*ptrA)[5][0] = 1; /* (*ptrA) is the array A. */
-
- The pointer to the array, as in the above, is useful for dynamically
- allocating multi-dimensional arrays or changes the starting address of any
- array.
-
- ---
- Phi-Long Tran
- ptran@asuvax.eas.asu.edu
- Arizona State University
-