www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/29/03:00:46

From: "Martin Ambuhl" <mambuhl AT tiac DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Strange error
Date: Mon, 29 Jun 1998 03:00:04 -0400
Organization: Nocturnal Aviation
Lines: 35
Message-ID: <6n7dum$4dj@news-central.tiac.net>
References: <3596BD1C DOT E64A50F6 AT earlham DOT edu>
NNTP-Posting-Host: p32.tc3.newyo.ny.tiac.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Walter Luke wrote in message <3596BD1C DOT E64A50F6 AT earlham DOT edu>...
:   I apologize--I'm a little new to C. Can anyone tell me why this
:segment of code produces an output of 900 when it is suppose to be 5?
===========
int attributes[1,1,1] uses a comma operator. This is not the way to do
multiple dimensions in C ( comma operators, where legal, represent
an ordered set of evaluations and the value of 1,1,1 is just the result of
the last evaluation: 1).  If you mean a 1x1x1 object it is declared
    int attributes[1][1][1];
Notice that there is exactly 1 element in a 1x1x1 object, namely
    attributes[0][0][0].

Martin Ambuhl (mambuhl AT tiac DOT net)
/* Newsgroup posts also e-mailed */
===========
:
:int attributes[1,1,1];
:int q;
:
:void initialize() {
:  attributes[1,1,1]=5;
:}
:
:main() {
:
:  initialize();
:  q=900;
:  printf("%d",attributes[1,1,1]);
:
:}
:
:


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019