Connecting Tech Pros Worldwide Help | Site Map

Array problem

  #1  
Old September 6th, 2006, 01:15 AM
Jing Yong
Guest
 
Posts: n/a
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, 03:55 AM
David Harmon
Guest
 
Posts: n/a

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, 04:05 AM
David Harmon
Guest
 
Posts: n/a

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, 11:05 AM
Frederick Gotham
Guest
 
Posts: n/a

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, 11:05 AM
Rolf Magnus
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array Problem When Index Value is Nothing Robert Bevington answers 3 June 27th, 2008 09:14 PM
Control Array Problem Toni answers 2 April 26th, 2007 06:05 AM
array problem julian_m answers 2 March 31st, 2006 11:45 AM
Array problem between Apache Server and .NET Client helldiversafe-news@yahoo.de answers 0 January 3rd, 2006 05:55 PM
array problem point answers 8 July 17th, 2005 02:29 AM