开发者

Storing changes made to an array of variables

开发者 https://www.devze.com 2023-04-12 23:08 出处:网络
I am storing the positions of players for a program i am writing to arrays stored as global variables, an example of which is:

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 开发者_C百科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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消