What is the difference between a static global and a static volatile variable?

后端 未结 7 2001
情歌与酒
情歌与酒 2020-12-08 04:58

I have used a static global variable and a static volatile variable in file scope,

both are updated by an ISR and a main loop and main loop checks the value of the varia

相关标签:
7条回答
  • 2020-12-08 05:34

    volatile variable means that the value assinged to it is not constant, i.e if a function containing a volatile variable "a=10" and the function is adding 1 in each call of that function then it will always return updated value. { volatile int a=10; a++; } when the above function is called again and again then the variable a will not be re-initialised to 10, it will always show the updated value till the program runs. 1st output= 10 then 11 then 12 and so on.

    0 讨论(0)
提交回复
热议问题