Array problem

J

Jing Yong

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[j]=0;

???

Thanks and regards,
yong jin
 
D

David Harmon

On 5 Sep 2006 17:22:41 -0700 in comp.lang.c++, "Jing Yong"
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[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.
 
D

David Harmon

On 5 Sep 2006 17:22:41 -0700 in comp.lang.c++, "Jing Yong"
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.)
 
F

Frederick Gotham

Jing Yong posted:
What is the difference between

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

and

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



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

Rolf Magnus

Jing said:
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[j]=0;

???


The first one is correct, the second isn't. Which compiler accepts for loops
with such a strange syntax?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,352
Latest member
SherriePet

Latest Threads

Top