c - Use the value of global variable in any other function as its value changes inside another function -
say using global variable hold value of signal (in schematics circuit board sense) in 1 function
void randomfunction() { for(t=lnnew,s=node->name;*s;) { if() //some code else *t=*s; t++; s++; } printf("%s \n",lnnew); //so here lnnew holding new values of signal , when print this, every time new value of signal printed , have declared global }
now how can use global variable inside other function writelnnewvalue()
when ever value of lnnew changes in randomfunction()
, changes , printed in writelnnewvalue ()
function?
i had asked similar type of question in this link , if seems exact copy mark duplicate.
you need declare variable in header (.h
file) included in compilation units use it:
extern volatile int lnnew;
have 1 compilation unit (.c
file) define it
volatile int lnnew;
then usable everywhere include header. volatile
here indicates compiler that variable subject unpredictable changes , not cached.
Comments
Post a Comment