Search This Blog

Wednesday, 13 December 2017

Post 3 Local/Global Variables and Logical Operators

Local/Global Variables

Global Variables are declared outside any function and they can be accessed (used) on any function in the program. Global variables then to very Unreliable and are used for quicker running code more than for reliable and stable code.
Local Variables however are declared inside a function and can be used only inside that function it's placed in.

float a = 1; --> The Global variable is declared outside the function "void my_test()"

void my_test() {

  float b = 77; --> This is the local variable and it is declared inside the known function
  println(a);

  println(b);


void setup() {

  float b = 2; --> This Local variable will not be able to be accessed by any other feature  and you will notice that Local variables names can be re-used as long as they're in different functions 

  println(a);
  println(b);
  my_test();
  println(b);

No comments:

Post a Comment

Post 6 Sequence,selection and iteration

Sequence Sequencing is when the computer will run the code it receives, one line at a time from the top to the bottom of the requested prog...