Re: for and arrays



"Bill Cunningham" <nospam@xxxxxxxxx> writes:

"Ben Bacarisse" <ben.usenet@xxxxxxxxx> wrote in message
news:87tzeh1rbu.fsf@xxxxxxxxxxxx
"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?

Well I tried and it compiled with no errors. Or atleast compiled
anyway.

You must have found out by now that a program that compiles is like an
essay the spell-checks. It does not mean you've answered the question.

Yes this is an excercise to learn.

Compiling it is not enough, then. The wonderful thing about
programming is that your program can tell you if you've got it right.

All I do is an excercise to learn. What
if one had an array of 500 ints and had the simple task of setting them
1-500? How's this for another take.

int a[10];
int b;
for (b=0;b<10;b++) {

a[ b=b+1];
}

Let's assume that you intended to write a[500] rather than a[10]. You
need to move one character characters to turn the above into
a program that does what you want, but can you see which character
needs to move at to where?

[I still think that you should learn an interpreted language.]

--
Ben.
.



Relevant Pages

  • Re: Is there any way in C to print =?ISO-8859-1?Q?=AE_=3F?=
    ... remember locales and wide character support was added in the 1994 amendment. ... indirection from 'int ' ... It compiles cleanly as a C99 program. ... The putwchar function is equivalent to putwc with the second ...
    (comp.lang.c)
  • Problem in compiling a C code with MSVC++6.00
    ... When I save the file as a cpp file, it compiles and runs ... int p1; ... void checkfile; ... printf("cannot allocate memory for elements!"); ...
    (comp.lang.c)
  • Re: Errors in compilation of simple programme
    ... using namespace std; ... cin>> i; ... it compiles without a problem on Visual C++ ... int main ...
    (microsoft.public.vc.language)
  • Re: Prime Numbers
    ... /*This code finally compiles as a 'c' code ... One more question....if i don't free up the memory allocated at the end ... it would appear that we are best served by an array ... prime numbers can be represented by an unsigned long int. ...
    (comp.lang.c)
  • Re: sizeof A
    ... inconsistencies of the language that you must ... With it being a character of course. ... it could be inconsistent. ... to int or unsigned int anyhow. ...
    (comp.lang.c)