From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: Q: Typedef riddle Date: Sat, 16 Nov 1996 12:44:45 -0800 Organization: Three pounds of chaos and a pinch of salt Lines: 39 Message-ID: <328E27BD.32@cs.com> References: <328DD331 DOT 26E4 AT stud DOT warande DOT ruu DOT nl> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp107.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: Elliott Oti To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Elliott Oti wrote: > > Hi, > I've been programming in C for a couple of years now and I thought > I knew at least the basics pretty well, but this has me stumped. > > Why does the following short little program output > > 10 > It's also 10 10 10 > > instead of > > 10 10 10 > It's also 10 10 10 > > It's not a gcc bug because Borland gives a similar output, > but -Wall gives absolutely no warnings. So what's wrong? > > void Dump(thing *V) > { > printf("\n%i %i %i\n",*V[0],*V[1],*V[2]); It took me a while to get it, but your problem is operator precedence. That line should read: printf( "\n%i %i %i\n", (*V)[0], (*V)[1], (*V)[2] ); The reason why should be obvious from this. :) -- John M. Aldrich, aka Fighteer I -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS d- s+:- a-->? c++>$ U@>++$ p>+ L>++ E>+ W++ N++ o+ K? w(---) O- M-- V? PS+ PE Y+ PGP- t+(-) 5- X- R+ tv+() b+++ DI++ D++ G e(*)>++++ h!() !r !y+() ------END GEEK CODE BLOCK------