fig:- Local and Global variable |
Similarly, a variable that is defined inside the function and is accessible to only the same function is called a local variable. Its initial value will be garbage value.
\n print a new line and %d print an integer value.
output
the value of the Global variable is 50
the value of the Local variable is 10
QUESTION: take the value of GLOBAL VARIABLE from the user and add it with the local variable.
output
the sum of the Global variable and local variable is 50
NOTE: if we are using the same name to define the variable in both local or global then we will get local variable value, but if we want to print global variable value then we have to use the "extern" keyword inside the function but if we want to print local variable then we can give a command print outside the int bracket function. let's be clear with the given function:-
Program
output
the value of global variable a is 50
the value of local variable a is 10
0 Comments