user61469: I'm trying to initialize an array globally which could be of different sizes according to future code in Arduino. 
int n=0;
int val[n];
This says that the array bound is not an integer constant before ']' token. This also says that the val variable wasn't declared.
I have browsed other forms and have been told to use dynamic storage usage which I don't know how to use. 
I'm trying to store different weight values respective to time in a variable. I first tried to store the weight in one variable but couldn't find the total weight etc.


user2967: As others have suggested, dynamically allocated memory is often problematic on a memory-starved device like an Arduino. As you create and release memory, the "heap" (a pool of memory to be used for that purpose) gets broken up into "islands" of free memory with still-used blocks of memory peppered throughout. 
In fairly short order you wind up with your available memory pretty much unusable, your app runs out of available memory, and your app crashes. 
This is known as "heap fragmentation". When you only have a couple of K of RAM to work with, it quickly becomes fatal.
If you can be sure that you allocate a dynamic buffer in a function call sequence, don't do any other dynamic memory allocation, and then free it before returning, you can probably get away with it without fragmentation, but you really have to be careful.
If you instead dynamically allocate a block of memory very early in your app's life and then keep it for the entire run that can be okay too. That block takes a chunk of your heap and just stays there.
A third alternative is to allocate a statically sized array at compile time that's big enough for your largest use, and treat that as a buffer. You can save contents there as needed, then when you're done with those contents, use the buffer for something else.

61469: <p>I'm trying to initialize an array globally which could be of different sizes according to future code in Arduino. <code>
int n=0;
int val[n];
</code>This says that the array bound is not an integer constant before ']' token. This also says that the val variable wasn't declared.</p>

<p>I have browsed other forms and have been told to use dynamic storage usage which I don't know how to use. </p>

<p>I'm trying to store different weight values respective to time in a variable. I first tried to store the weight in one variable but couldn't find the total weight etc.</p>

<p><a href="https://i.stack.imgur.com/vT9yi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vT9yi.png" alt="enter image description here"></a></p>
 2967: <p>As others have suggested, dynamically allocated memory is often problematic on a memory-starved device like an Arduino. As you create and release memory, the "heap" (a pool of memory to be used for that purpose) gets broken up into "islands" of free memory with still-used blocks of memory peppered throughout. </p>

<p>In fairly short order you wind up with your available memory pretty much unusable, your app runs out of available memory, and your app crashes. </p>

<p>This is known as "heap fragmentation". When you only have a couple of K of RAM to work with, it quickly becomes fatal.</p>

<p>If you can be sure that you allocate a dynamic buffer in a function call sequence, don't do any other dynamic memory allocation, and then free it before returning, you can probably get away with it without fragmentation, but you really have to be careful.</p>

<p>If you instead dynamically allocate a block of memory very early in your app's life and then keep it for the entire run that can be okay too. That block takes a chunk of your heap and just stays there.</p>

<p>A third alternative is to allocate a statically sized array at compile time that's big enough for your largest use, and treat that as a buffer. You can save contents there as needed, then when you're done with those contents, use the buffer for something else.</p>
