Algorithms - EduqasLocal and global variables

Algorithms are step-by-step plans for solving problems. They are a starting point when writing a program. Algorithms can be designed using pseudo-code and flowcharts.

Part ofComputer ScienceUnderstanding Computer Science

Local and global variables

A is one that can be accessed and changed throughout the whole , including .

are confined to a subroutine (but some do allow them to be declared within a ). The key point is that local variables cannot be accessed from outside the code section that they are declared in. This means that the programmer can use the same variable names for different purposes in different parts of the program.

The lifetime of a variable

The lifetime of a variable describes how long that variable exists. A global variable will start to exist when it is first defined and will cease to exist when the program ends. A local variable exists only within the subroutine in which it is defined. It will cease to exist when the subroutine ends. This means that can be reused throughout the program execution.