home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!usenet-feed.cc.umr.edu!mcs213c.cs.umr.edu!ckincy
- From: ckincy@mcs213c.cs.umr.edu (Charles Kincy)
- Subject: Re: Novice Questions
- References: <1992Aug30.004740.8973@eskimo.celestial.com> <1992Aug30.101121.4479@klaava.Helsinki.FI>
- Date: Sun, 30 Aug 1992 22:14:26 GMT
- Nntp-Posting-Host: mcs213c.cs.umr.edu
- Organization: University of Missouri - Rolla
- Sender: cnews@umr.edu (UMR Usenet News Post)
- Message-ID: <1992Aug30.221426.9849@umr.edu>
- Lines: 29
-
- In article <1992Aug30.101121.4479@klaava.Helsinki.FI> wirzeniu@klaava.Helsinki.FI (Lars Wirzenius) writes:
- >maven@eskimo.celestial.com (Norman Hamer) writes:
- >> 1. Given a char array, say char foo[256];, is *foo the same as foo[0]
- >>and is foo+x the same as foo[x] in all implementations?
- >
- >*foo and foo[0] are identical, and *(foo+x) and foo[x] are identical.
- >The latter is by definition: the language is defined that way. The
- >former follows directly from the latter: foo[0] <=> *(foo+0) <=> *(foo)
- ><=> *foo.
-
- Beware! If you define foo as a char[], you may not reassign foo in
- any way or you will be punished by a wet noodle. =)
-
- Example:
- char foo[256];
- char *roo = "Argh!";
- [...]
- foo = roo;
-
- Don't do this!!!
-
- Do this:
-
- strcpy(foo, roo);
-
- Many novices fall into this trap. Arrays and pointers are *nearly*
- equivalent, but not quite.
-
- cpk
-