home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18885 < prev    next >
Encoding:
Text File  |  1993-01-10  |  1.8 KB  |  67 lines

  1. Path: sparky!uunet!usc!sdd.hp.com!think.com!enterpoop.mit.edu!eru.mt.luth.se!lunic!sunic!aun.uninett.no!nuug!nntp.nta.no!nntp.nta.no!rune
  2. From: rune@nta.no (Rune Henning Johansen FBA)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Passing 2-d arrys to functions
  5. Message-ID: <RUNE.93Jan10125255@pandora.nta.no>
  6. Date: 10 Jan 93 11:52:55 GMT
  7. References: <C0Hw4n.Hy9@knot.ccs.queensu.ca> <C0H9sA.BGw@newsserver.technet.sg>
  8.     <24568@alice.att.com> <726521188snx@trmphrst.demon.co.uk>
  9. Sender: news@nntp.nta.no
  10. Organization: Norwegian Telecom Research
  11. Lines: 52
  12. In-Reply-To: nikki@trmphrst.demon.co.uk's message of Fri, 8 Jan 1993 12:26:28 +0000
  13. Nntp-Posting-Host: pandora.nta.no
  14.  
  15. In article <726521188snx@trmphrst.demon.co.uk> nikki@trmphrst.demon.co.uk (Nikki Locke) writes:
  16.  
  17.   >  For a two (or more) dimensional array, to access element [m][n], the 
  18.   >  compiler needs to know the address of the first element, the size of each 
  19.   >  element, and the number of elements in the least significant dimension. 
  20.   >  The calculation for an array declared [DIM1][DIM2] is 
  21.   >  ((m * DIM2 + n) * sizeof(element)).
  22.  
  23. I'm including a little program that seems to work fine. Here I'm pas-
  24. sing only the pointer to  a two dimensional array.  Can I expect such
  25. programs to work, and if so, why?
  26.  
  27.  - Rune
  28.  
  29.  = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  30.  
  31. #include <stream.h>
  32.  
  33. #define begin {
  34. #define end   }
  35.  
  36. void Input ( double **b )
  37. begin
  38.     b[0][0] = 1.0;
  39.     b[1][0] = 2.0;
  40.     b[0][1] = 3.0;
  41.     b[1][1] = 4.0;
  42. end
  43.  
  44. void Output ( double **b )
  45. begin
  46.     cout << b[0][0] << "\n";
  47.     cout << b[1][0] << "\n";
  48.     cout << b[0][1] << "\n";
  49.     cout << b[1][1] << "\n";
  50. end
  51.  
  52. int main ()
  53. begin
  54.     double **a = new double*[2];
  55.     a[0] = new double[2];
  56.     a[1] = new double[2];
  57.  
  58.     Input  ( a );
  59.     Output ( a );
  60.  
  61.     delete a[0];
  62.     delete a[1];
  63.     delete a;
  64.  
  65.     return 0;
  66. end
  67.