1) Since the data cannot be accessed from other functions, data integrity is preserved. 2) Only required data can be passed to function, thus protecting the remaining data.
S
Its not that the compiler can't initialize local variables; its that the compiler does not initialize local variables.This is by design and language specification. If you want to initialize local variables, you must explicitly do so.
Global variables can be seen in all blocks of your program, when local variables are visible only within the block where it's declared.
Auto variables are stored on the stack alongside all other local variables.
Only global/static variables are, local variables aren't.
Stack.
Stack.
1. Local variables cannot be used by other forms. 2. Cannot be used globally. 3. They can slowdown the compiling process.
Faster execution of code.
Local Variables There are two types of variables based on the location of declaration 1. Instance Variables- Declared inside a class, but outside of any method's body. 2. Local Variables- Declared inside a method's body inside a class.
On the stack.
The variables which are declared outside the main() function is known as global variables and they can be used anywhere in the program. And, the variables which used declare inside the main() function is known as local variables and they can be used inside the main() function only. Example: #include<stdio.h> #include<conio.h> int x,y; // global variables void main() { int a,b; // Local variables ------------ ---------------------- --------------------- getch(); }