Mail Archives: djgpp/1998/06/29/03:00:46
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 -