home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16721 < prev    next >
Encoding:
Text File  |  1992-11-18  |  1.7 KB  |  56 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!think.com!rpi!ghost.dsi.unimi.it!itnsg1.cineca.it!ditolla
  3. From: ditolla@itnsg1.cineca.it (Francesco Di Tolla)
  4. Subject: Re: What is meant by: double A[n,m]?
  5. Message-ID: <1992Nov18.125904.25326@itnsg1.cineca.it>
  6. Organization: Laboratorio di Fisica Computazionale, INFM. Trento Italia
  7. References: <TORSTEIN.92Nov18125146@itekiris.kjemi.unit.no>
  8. Date: Wed, 18 Nov 1992 12:59:04 GMT
  9. Lines: 45
  10.  
  11. torstein@itekiris.kjemi.unit.no (torstein hansen) writes:
  12.  
  13. >As a newcomer to C, previously programming in Pascal, I used the
  14. >following declaration in one of my programs:
  15.  
  16. >double A[n,m];
  17.  
  18. >I assumed (erronously) that this would give a n by m matrix. But
  19. >obviously, it didn't.  But the compiler never gave any errors or
  20. >warnings, and using 
  21.  
  22. >  A[rownumber,colnumber]=some_value;
  23. >was also accepted by the compiler.  I'm not asking for the correct 
  24. >way to define an array, I found that out quickly, but what is meant 
  25. >by A[n,m]?  It seems like the compiler just ignores the n and makes 
  26. >it A[m].  This is also the case when assigning values to the array.
  27.  
  28. In c 'n,m' is an expression which has the value of m because expressions
  29. separated by commas are evluated from left to right and only the last
  30. value is kept:
  31.  
  32. exp1, exp2, ....,expN;
  33.  
  34. this evaluets to expN.
  35. so
  36.  
  37. a=(b=5,b+1);
  38.  
  39. will assign 5 to b and 6 to the a in a way which is harder to understand than
  40.  
  41. b = 5;
  42. a = b + 1;
  43.  
  44. >Torstein Hansen
  45. >torstein@itekiris.kjemi.unit.no
  46.  
  47.  
  48. Bye
  49. Franz
  50. -- 
  51.  --------------------------------------------------------------------------
  52. |  Francesco  D. Di Tolla            | Intern. School for Advanced Studies |
  53. |  Dip. di Fisica Univ. di Trento    | SISSA/ISAS via Beirut, 2-4          |
  54. |  I-38050 Povo (TN)                 | I-34013 Trieste                     |
  55.