Re: for and arrays



"Bill Cunningham" <nospam@xxxxxxxxx> writes:

I understand this code.

int a[5];
int b;
for (b=0;b<5;b=b+1)
int a[b];

Did you try?

This should take every element of the array a and set it to 1,2,3,4,5.
Great.

No, a loop that "sets" things will usually have an assignment in its
body.

Now for the big question. How would you work this?

int a [5][3];

And make the first element of 5 all zeros and the second element of 3 equal
to 1,2,3 ? I don't know how to work with a 2 dimensional array.

I'd stick with 1 dimensional ones. If you are in this for the
challenge of learning C, then it is much better to master the easy
bits before moving on. If you have some objective in mind (i.e. you
want to write some specific program) then you should pick a language
with fewer pitfalls and peculiarities than C. In particular,
interpreted languages let you learn by trying things out which, I
suspect, is a style that would suit you.

--
Ben.
.



Relevant Pages

  • Re: System.arraycopy (2 dim array) and growth of 2 dim array
    ... I am working on a program which contains a module that can perform Cartesian ... int pubnewlength; ... System.arraycopy(a, 0, newArray, 0, length); ... How can I use system.arraycopy to copy my two dimensional array? ...
    (comp.lang.java.programmer)
  • System.arraycopy (2 dim array) and growth of 2 dim array
    ... I am working on a program which contains a module that can perform Cartesian ... int pubnewlength; ... System.arraycopy(a, 0, newArray, 0, length); ... How can I use system.arraycopy to copy my two dimensional array? ...
    (comp.lang.java.programmer)
  • Re: returning array
    ... >> How to return an two dimensional array in user defined function to main ... This should be int main; ... You don't tell us what the value of rows and cols are. ... you don't specify the number of columns. ...
    (comp.lang.c)
  • Re: returning array
    ... >>> How to return an two dimensional array in user defined function ... > This should be int main; ... Those are global variables that are set during the call to enter. ... It's also used to exit loops, ...
    (comp.lang.c)
  • Passing a 2-dimensional array
    ... Earlier I asked a question about passing an array to a user defined ... I need to pass a 2 dimensional array and I tried but cannot figure out how ... extern void fillArray (int arrayQuizzes[], int numStudents, int numQuizzes); ...
    (alt.comp.lang.learn.c-cpp)