No products in the cart.

difference between local and global variable

CBSE, JEE, NEET, CUET

CBSE, JEE, NEET, CUET

Question Bank, Mock Tests, Exam Papers

NCERT Solutions, Sample Papers, Notes, Videos

difference between local and global variable
  • 1 answers

Sia ? 3 years, 5 months ago

<th>Global Variable</th> <th>Local Variable</th>
Global variables are declared outside all the function blocks. Local Variables are declared within a function block.
The scope remains throughout the program. The scope is limited and remains within the function only in which they are declared.
Any change in global variable affects the whole program, wherever it is being used. Any change in the local variable does not affect other functions of the program.
A global variable exists in the program for the entire time the program is executed. A local variable is created when the function is executed, and once the execution is finished, the variable is destroyed.
It can be accessed throughout the program by all the functions present in the program. It can only be accessed by the function statements in which it is declared and not by the other functions.
If the global variable is not initialized, it takes zero by default. If the local variable is not initialized, it takes the garbage value by default.
Global variables are stored in the data segment of memory. Local variables are stored in a stack in memory.
We cannot declare many variables with the same name. We can declare various variables with the same name but in other functions.
http://mycbseguide.com/examin8/

Related Questions

Define packages
  • 0 answers
What is alu
  • 1 answers
Write a program for swapping two numbers?
  • 0 answers
Write a program for swapping two numbers
  • 1 answers

myCBSEguide App

myCBSEguide

Trusted by 1 Crore+ Students

Test Generator

Test Generator

Create papers online. It's FREE.

CUET Mock Tests

CUET Mock Tests

75,000+ questions to practice only on myCBSEguide app

Download myCBSEguide App