c - changing variable value from within a function -


i'm writing program in c in need change value of variable within function.

i've tried setting variable globally not recognized withinn function

so tried following: variable nobuttons:

readconfig(config2, &nobuttons);  void readconfig(file * config, int * buttons) {     buttons = 5; } 

when print value of buttons, it's shown 0(the value initialized to)

what doing wrong?

use *buttons = 5; instead of buttons = 5;

when print value of buttons, it's shown 0(the value initialized to)

the value of button not initialized know, global variables default initialized 0 hence 0 when print it.

buttons=5; means address of buttons pointer holding address 5 whereas, *buttons = 5; means content of buttons pointer changed value 5. remember, content of whom buttons pointer points updated 5 now.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -