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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!sun-barr!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!princeton!newross!dynastar!blume
  3. From: blume@dynastar.Princeton.EDU (Matthias Blume)
  4. Subject: Re: Novice Questions
  5. Message-ID: <1992Aug31.210244.21471@newross.Princeton.EDU>
  6. Sender: news@newross.Princeton.EDU (USENET News System)
  7. Reply-To: blume@dynastar.Princeton.EDU (Matthias Blume)
  8. Organization: Dept. of Computer Science, Princeton University
  9. References: <1992Aug30.004740.8973@eskimo.celestial.com>  <1992Aug31.093741.132@physc1.byu.edu>
  10. Date: Mon, 31 Aug 1992 21:02:44 GMT
  11. Lines: 38
  12.  
  13. In article <1992Aug31.093741.132@physc1.byu.edu>,
  14. robertson@physc1.byu.edu writes:
  15. |> In article <1992Aug31.070123.23997@klaava.Helsinki.FI>,
  16. wirzeniu@klaava.Helsinki.FI (Lars Wirzenius) writes:
  17. |> > Arrays and pointers are nowhere near equivalent.  Superficially they
  18. |> > might look so, but that is only because arrays usually automatically
  19. |> > become pointers in C (but sometimes don't).  For more information,
  20. |> > please read the FAQ of this group, section 2 especially.
  21. |> > 
  22. |> > Btw, the person who said that array names are constant pointers might
  23. |> > want to look at questions 2.6.
  24. |> 
  25.  
  26. Sorry for bothering you -- I was the person who said this.
  27. Of course, I knew about the differences. I merely tried to
  28. suggest a simple ``rule of thumb'', how C novices might remember
  29. the most appearent difference between pointers and arrays:
  30. An array is not a lvalue! But most of the time, expressions of
  31. type ``array of T'' are converted to type ``pointer to T'', so
  32. it appears as if array-names were pointers.
  33. Here is the appropriate quote from K&R2 (page 200,
  34. App. A, par. A7.1 "pointer generation"):
  35.  
  36.     "If the type of an expression is 'array of T,' for some
  37.     type T, then the value of the expression is a pointer to
  38.     the first object in the array, and the type of the
  39.     expression is altered to 'pointer to T.'  This conversion
  40.     does not take place if the expression is the operand to
  41.     the unary & operator, or of ++, --, sizeof, or as the
  42.     left operand of an assignment operator or the . operator.
  43.     Similarly, an expression of type 'function returning T,'
  44.     except when used as the expression operand of the & operator,
  45.     is converted to `pointer to function returning T.'"
  46.  
  47.  
  48. -Matthias
  49.  
  50.  
  51.