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

What is the difference between dataadapter and datareader?

0 Answers  


Where views are stored in sql server?

0 Answers  


what are questions asked in TCS for database tester (sqlserver)for 2-3 exp?

0 Answers   ABC, TCS,


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.

3 Answers  


What is data file in computer?

0 Answers  






How to Insert multiple rows with a single insert statement?

0 Answers  


How to move database physical files in ms sql server?

0 Answers  


What are the dmvs?

0 Answers  


What is indexing in sql server with example?

0 Answers  


How to loop through result set objects using odbc_fetch_row()?

0 Answers  


Explain the collation?

0 Answers  


how to avoid cursors? : Sql server database administration

0 Answers  


Categories