Saturday 15 March 2014

c - Does values of global variable changes if they are updated in function? -


Actually I've written this code but it is not working. Please plz me Unsigned short investigation Collins orphood (unsigned short line head, unsigned short callhead) / This function is otherwise the main function where I am changing the value of "line head", but only after checking it Resides * / {if (turn == 0) {if (address [callhide] & amp; (1 & lt; & lt; ((line head + 1)% 8) {if (((int () ( Address [(colHead + 7)% 8] & amp; (1 & lt; & lt; (rowHead + 1)% (8)) + (et) (address [collide] & amp; (1 & lt; & lt ; (Line Head + 2)% 8)) + (Int) (Address [[CoHeld + 1]% 8] & amp; (1 & lt; & lt; (Line Head + 1)% 8))) & gt; ; 1) Return This value of -1; Else {rowHead = (rowHead + 1)% 8; // rowHead does not change. Return1;}}}

variable "turn", " Line head "," callhead "are global variables, now after modifying this code according to the instructions of Daniel Fisher, it is

  unsigned short-check Collins orphood () {if (turn == 0 ) {If (address [colhead] & amp; (1 & lt; ((line row + 1)% 8)) {if ((int (address [(colahhead + 7)% 8] Amp; (1 & lt; & lt; (rowHead + 1)% 8)) + (int) (address [collide] & amp; (1 & lt; & lt; (rowHead + 2)% 8)) + (integer) (address [[Coleyhead + 1]% 8] & amp; (1 & lt;    

your function parameters

  Unsigned short check collins orfood (unsigned short line head, unsigned short callhead)   

Shadow is global (file radius, in fact) variables of the same name, therefore, in the work, you only pass The copies change logic, which has no effect outside the function. In the function, you can not access shadowed global variables (without some gymnastics).

The point of the global variable is that they do not need to be passed as arguments (or not indicated as them) because they can be accessed without it.

No comments:

Post a Comment