Reflection: Scope Variables
I, Summary
There are two types of c variables.
- Local
- Global
II, Applied to solve problems
When I remember the differences between local and global variable, I can use it a suitable way. When I understand the differences between pass parameters by values and by references, I won't have some mistake about them. When I know it, my program can return more than 2 values. It makes me happy and excited.
There are two types of c variables.
- Local
- Global
Local variables:
Variable whose existence is known only to the main program or functions are called local variables. Local variables are declared with in the main program or a function.
Global variables:
Variables whose existence is known to the both main() as well as other functions are called global variables. Global variables are declared outside the main() and other functions.
Difference between Local and Global c variables:
- Local c variable is declared in functions and blocks, while global c variables are declared outside functions and blocks.
- Local c variables can be accessed only that function and blocks which declared it, while global c variables can be accessed within all program.
- Local c variables when declared not initialized automatically by system you have to declared it, while global c variables when declared initialized automatically by system. Int is initialized as 0, char as ‘’ etc.
- Implement functions to demonstrate the differences between local and global variablesExample1:Example2:Example3:
- Implement functions to demonstrate the differences between pass parameters by values and by references
When I remember the differences between local and global variable, I can use it a suitable way. When I understand the differences between pass parameters by values and by references, I won't have some mistake about them. When I know it, my program can return more than 2 values. It makes me happy and excited.
Comments
Post a Comment