What is the difference between a local and a global variable?
Answers were Sorted based on User's Feedback
Answer / rahul
Local Variables are declared within the function main.
main()
{
int a,b,c;(local variable declaration)
}
Global variables are declared outside the function main.
int FACT(int);
main()
{
Local variable declaration;
}
Is This Answer Correct ? | 128 Yes | 16 No |
Local Variable :
The scope or lifetime of the local variable
is with in a block or procedure..
Eg: DECLARE @Variable1
Global Variable :
The scope or lifetime of the global
variable throughout the execution of the program..
Eg: DECLARE @@Variable1
Is This Answer Correct ? | 119 Yes | 23 No |
Answer / l.pandiyan
A global variable can be accessed by all functions. It is
initialized at the beginning of the program and is deleted
when the program shuts down. A local variable is isolated in
its function.
Is This Answer Correct ? | 70 Yes | 6 No |
Answer / rattana
global variable can be accessed by all functions. local variable is isolated in its function.It is initialized at the beginning of the program and deleted when the program closed.
Is This Answer Correct ? | 31 Yes | 10 No |
Answer / jaccessdenied
int a;//global variable
class VariablesDemo
{
int b;//class variable
void add()
{
int c,d;//c,d,e are local variables that are used within the function add
int e=c+d;
}
}
Is This Answer Correct ? | 17 Yes | 6 No |
What is the difference between dataadapter and datareader?
Where views are stored in sql server?
what are questions asked in TCS for database tester (sqlserver)for 2-3 exp?
employee table has employee id ----------- empid ---------------- 1 2 3 3 3 4 5 5 5 6 6 6 7 here the values r repeated two times.how to select the repeated values only.i.e 3,5,6 should alone come.
What is data file in computer?
How to Insert multiple rows with a single insert statement?
How to move database physical files in ms sql server?
What are the dmvs?
What is indexing in sql server with example?
How to loop through result set objects using odbc_fetch_row()?
Explain the collation?
how to avoid cursors? : Sql server database administration