Wrong code

 

Hi guys,


This is my simple code:

   int num[];
   int i=0;
   for(i=0;i<10;i++) 
      { 
      num[i]=i;
      Print(num[i]);
      }
All prints are 0. Why? Why not 0, 1, 2, 3, 4 ... etc?
 

No storage space declared for array.

Change

int num[];

to

int num[10]; // minimum 10, since you will use 10 elements of storage in your code

and retest

 
phy:

No storage space declared for array.

Change

int num[];

to

int num[10];

and retest

Thank you phy!

 
ggekko:

Thank you phy!

Let me a new question: what will be the code, if I dont know previously the number of items in the array?

 
 
phy:

ArrayResize()

Thanks phy!

Reason: