| www.delorie.com/archives/browse.cgi | search |
| From: | Nate Eldredge <neldredge AT hmc DOT edu> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Re: How do I access elements of a structure with pointers? |
| Date: | Mon, 11 Oct 1999 16:11:37 -0700 |
| Organization: | Harvey Mudd College |
| Lines: | 34 |
| Message-ID: | <38026EA9.9CEC2C61@hmc.edu> |
| References: | <7ttpdq$97ag8$1 AT titan DOT xtra DOT co DOT nz> |
| NNTP-Posting-Host: | mercury.st.hmc.edu |
| Mime-Version: | 1.0 |
| X-Trace: | nntp1.interworld.net 939683541 75275 134.173.45.219 (11 Oct 1999 23:12:21 GMT) |
| X-Complaints-To: | usenet AT nntp1 DOT interworld DOT net |
| NNTP-Posting-Date: | 11 Oct 1999 23:12:21 GMT |
| X-Mailer: | Mozilla 4.61 [en] (X11; U; Linux 2.2.13pre12 i586) |
| X-Accept-Language: | en |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
Nicholas Parker wrote:
>
> This seems a fundamental part of C, but alas I don't know how to do this,
> arbitrary code follows;
> ----------------------------------------
> typedef struct {
> float re;
> float im;
> } complex;
>
> void main(void){
> complex nick[4];
> complex *parker;
> parker=&nick[0];
>
> *parker.re=3; // This line wrong
> }
> --------------------------------------------
>
> How do I access elements of nick with a pointer is
> how do I set parker.re (that is; nick[0].re ?)
The . operator has a higher precedence than *, so you must parenthesize.
(*parker).re=3;
As an alternative (and much more commonly used) syntax, C provides the
-> operator. The above is equivalent to
parker->re=3.
--
Nate Eldredge
neldredge AT hmc DOT edu
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |