开发者

How to declare a variable to be accessed by two functions in C?

I have this boolean variable that need to be access开发者_如何转开发ed by two functions. In C programming, instead of declaring as global variable, is there any other way?


No there is not. This is what global variables are for.


You can send the value as a parameter if you only need your two functions to read the variable.

If you also need to change the variable from within the function, you will need to either use a global variable, or to send a pointer to the variable (which could be declared locally in whatever function ends up calling these other functions).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜