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 |
How to check what was the last restore transaction LSN on Log-Shipping and Mirroring when we doesn't have a Monitor server and Witness server?
How global temporary tables are represented and its scope?
i have 4 tables.. T1, T2, T3, T4.. these tables have the same structure and they store the information entered in different years.. T1 stored 2002, T2 stored 2003, T3 stored 2004 and T4 stored 2005.. i want to copy contents in T1 to T2, T2 to T3, T3 to T4 and T4 to T1.. how do i do that? Temp tables cannot be used..
What is blocking and how would you troubleshoot it?
What are the properties of the transactions?
How to reaname table name without using sp_Rename in sql server..?
What are different types of raid levels?
Tell me what is sql profiler?
What is the maximum size of a row in sql server?
What do you understand by sql server agent?
What is blocking in SQL Server? If this situation occurs how to troubleshoot this issue
What are alternate keys?