What is the difference between a local and a global variable?

Answers were Sorted based on User's Feedback



What is the difference between a local and a global variable?..

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

What is the difference between a local and a global variable?..

Answer / thiyagaraj.ramaswamy

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

What is the difference between a local and a global variable?..

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

What is the difference between a local and a global variable?..

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

What is the difference between a local and a global variable?..

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

Post New Answer

More SQL Server Interview Questions

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?

2 Answers   IBM,


How global temporary tables are represented and its scope?

0 Answers  


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..

4 Answers  


What is blocking and how would you troubleshoot it?

3 Answers   HCL,


What are the properties of the transactions?

0 Answers  






How to reaname table name without using sp_Rename in sql server..?

0 Answers   Wipro,


What are different types of raid levels?

0 Answers  


Tell me what is sql profiler?

0 Answers  


What is the maximum size of a row in sql server?

0 Answers  


What do you understand by sql server agent?

0 Answers  


What is blocking in SQL Server? If this situation occurs how to troubleshoot this issue

2 Answers   IBM,


What are alternate keys?

0 Answers  


Categories