Reload initialized value


I wonder if its possible to reload or reassign the initialized value of a variable during run-time without restart?

Let us say i have an int array that is initialized at declaration as follow:

 int myvar[5] = {10, 20, 30, 40, 50};

Now during the execution of the code all elements of myvar[] takes on new values. How can i reassign the above values to all elements of myvar[] at some point in time while the code is in execution without going through the power-on cycle?

Any help is great.

Just assign them. I don't understand your confusion.

myvar[0] = 10;
myvar[2] = 20;
// ...etc

The confusion more than likely comes because the initialisation uses {} which can not be used at run time.

The confusion is that how would the code know what was the initialized value of a variable once the code started to execute?

i don't want to manually do the assignment again instead i am looking for some way such that the initialized valued that was assigned at the declaration is reassigned once again to the variable just like as if the variable is declared again but without explicitly initializing again with an assignment.

i tried to convey my point but if its not clear, pls. tell i will explain it again.

No. you can't do that. You could store the initial values in another variable so you still have a copy. Or you could hard code the values. This is an X-Y question. Describe what you actually want to accomplish, not how you erroneously though you might go about getting there.

i think the initialized values are saved in the program memory along with the code. so they would be there all the time permanently saved in PROM space.
And there should be some way to get to those values and load them while the code is in execution. Obviously if those values are loaded at the startup time then they can also be loaded later on.
Any help… or my thinking is on some wrong tangent?

Ok. I gave you two options that would work. If you want to keep banging your head against this until you've convinced yourself it's not going to happen then go ahead.

If you want help any more specific than you've got so far thenpost some code and details about what should happen.

Your compiled code will probably contain something in the line of (C equivalent)

int *ptr;
ptr = myvar;
*ptr = 10;
*ptr = 20;

You can always look at the generated assembly code to see what really is generated.