Connecting Tech Pros Worldwide Help | Site Map

Array problem

 
LinkBack Thread Tools Search this Thread
  #1  
Old September 6th, 2006, 12:15 AM
Jing Yong
Guest
 
Posts: n/a
Default Array problem

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


  #2  
Old September 6th, 2006, 02:55 AM
David Harmon
Guest
 
Posts: n/a
Default 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.


  #3  
Old September 6th, 2006, 03:05 AM
David Harmon
Guest
 
Posts: n/a
Default 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.)

  #4  
Old September 6th, 2006, 10:05 AM
Frederick Gotham
Guest
 
Posts: n/a
Default 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
  #5  
Old September 6th, 2006, 10:05 AM
Rolf Magnus
Guest
 
Posts: n/a
Default 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?


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.