user993393
user993393

Reputation: 1

Storing changes made to an array of variables

I am storing the positions of players for a program i am writing to arrays stored as global variables, an example of which is:

float motor1[] = {4.312, 27.312};

Any time a move is made, I have functions called checkposition, move player and update position that retrieve and update this array. All of these functions are in one module called motor.c and have a hierarchy in which they are performed. I have a main module main.c which calls on this module and passes it some information and the motor.c processes it and then spits out an answer. The thing that confuses me is that since the array is saved as a global variable does that mean that it is initialized every time this module is called? Which would mean that my update position function would never work beyond the first move.

Upvotes: 0

Views: 41

Answers (2)

MByD
MByD

Reputation: 137312

No, a global variable is initialized when the program start up (and only then)

Upvotes: 1

NPE
NPE

Reputation: 500317

No, if it's a global variable, it gets initialized just once, on program startup.

Upvotes: 1

Related Questions