Connecting Tech Pros Worldwide Forums | Help | Site Map

Array problem

Jing Yong
Guest
 
Posts: n/a
#1: Sep 6 '06
My first course in computer programming,

I still use VC6 as a C compiler at school and this draws a little
attention to the basics I stumble at,
what is the difference between

int a[100][100]={0};

and

for(int i=0->100)
for(int j=0->100)
a[i][j]=0;

???

Thanks and regards,
yong jin


David Harmon
Guest
 
Posts: n/a
#2: Sep 6 '06

re: Array problem


On 5 Sep 2006 17:22:41 -0700 in comp.lang.c++, "Jing Yong"
<denmark88888@yahoo.dkwrote,
Quote:
>My first course in computer programming,
>
>I still use VC6 as a C compiler at school and this draws a little
>attention to the basics I stumble at,
>what is the difference between
>
>int a[100][100]={0};
>
>and
>
>for(int i=0->100)
for(int j=0->100)
a[i][j]=0;
You may regard the difference as being that in the first case the
compiler generates a huge block of zeros that gets loaded in to
memory at initialization time, while in the second case the compiler
generates a small bit of executable code to write zeros to the array
at run time. In reality, depending on your compiler and its
optimization strategy, it can do anything it wants as long as you
end up with the right result.


David Harmon
Guest
 
Posts: n/a
#3: Sep 6 '06

re: Array problem


On 5 Sep 2006 17:22:41 -0700 in comp.lang.c++, "Jing Yong"
<denmark88888@yahoo.dkwrote,
Quote:
>for(int i=0->100)
for(int j=0->100)
(that's not actually anything like the C++ -operator,
but I assume you mean the conventional for loop.)

Frederick Gotham
Guest
 
Posts: n/a
#4: Sep 6 '06

re: Array problem


Jing Yong posted:
Quote:
What is the difference between
>
int a[100][100]={0};
>
and
>
for(int i=0->100)
for(int j=0->100)
a[i][j]=0;

The former is valid C or C++, the latter isn't.

--

Frederick Gotham
Rolf Magnus
Guest
 
Posts: n/a
#5: Sep 6 '06

re: Array problem


Jing Yong wrote:
Quote:
My first course in computer programming,
>
I still use VC6 as a C compiler at school and this draws a little
attention to the basics I stumble at,
what is the difference between
>
int a[100][100]={0};
>
and
>
for(int i=0->100)
for(int j=0->100)
a[i][j]=0;
>
???
The first one is correct, the second isn't. Which compiler accepts for loops
with such a strange syntax?


Closed Thread