Computer Science for IGCSE & O level - Programming (Section 3 - No. 16)

What is the main difference between a local and a global variable?
Local variables can be used anywhere in the program, and global variables can only be used in a single function.
Global variables are only for numbers, and local variables are for text.
Local variables are declared inside a function, and global variables are declared outside any function.
Local variables are more efficient than global variables.

Explanation

The key difference is their scope - where they can be accessed in the code.

Comments (0)

Advertisement