home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 12913 < prev    next >
Encoding:
Text File  |  1992-08-29  |  1.4 KB  |  40 lines

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