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

explain different types of backups avaialabe in sql server? Given a particular scenario, how would you go about choosing a backup plan? : Sql server database administration

0 Answers  


Difference between primary key and clustered index?

0 Answers  


what is the sql equivaent of the dataset relation object ?

0 Answers  


What is attribute relationships, why we need it? : sql server analysis services, ssas

0 Answers  


What is difference between materialized view and view?

0 Answers  






Can an automatic recovery be initiated by a user?

0 Answers  


Explain what is the use of custom fields in report?

0 Answers  


Do you know what is normalization of database? What are its benefits?

0 Answers  


Explain what are the database objects? : SQL Server Architecture

0 Answers  


If a stored procedure is taking a table data type, how it looks?

1 Answers  


What is an index in sql?

0 Answers  


What is temporal data type?

0 Answers  


Categories