CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Our Services
Get 9,000 Interview Questions & Answers in an eBook.




Get it now !!
Send your Resume to 6000 Companies

Search Interview Questions

Question: Difference between : -
1)Global variable and Local variable ,
2)Static variable and Global variable ?

Answer: 1)Global variable and Local variable-
A) Global variables once declared they can be used any where in the program i.e. even in many functions. If possible u can use the global variables in the different user defined header files as like in packages in java.
On the other hand global variables values can be changed programmatically

local variables are local to a functional and cant be used beyond that function.


2)Static variable and Global variable ?
Static variables once declared they remain the same in the entire program. and those values cant be changed programatically.

global variables: check above description



Category Variables in C Interview Questions & Answers - Exam Mode / Learning Mode
Rating (3.8) By 48 users
Added on 11/22/2013
Views 710
Rate it!
Question: Difference between : -
1)Global variable and Local variable ,
2)Static variable and Global variable ?

Answer:

1)Global variable and Local variable-
A) Global variables once declared they can be used any where in the program i.e. even in many functions. If possible u can use the global variables in the different user defined header files as like in packages in java.
On the other hand global variables values can be changed programmatically

local variables are local to a functional and cant be used beyond that function.


2)Static variable and Global variable ?
Static variables once declared they remain the same in the entire program. and those values cant be changed programatically.

global variables: check above description Source: CoolInterview.com

Answered by: raj | Date: 11/22/2008 | Contact raj Contact raj

1) Global variables scope is defined for the entire program, but local variables scope exists only for the block in which it is defined.
2) Any global variable can be accessed in the entire program, whereas the scope of the static variable is global, but can be modified only in the block in which it is defined. Static variables shields the variable to accessed by any other parts of the program.

And regarding the memory details global and static variables are created on heap by the compiler, but the local variables are created on stack. Source: CoolInterview.com

Answered by: rakifriend | Date: 11/23/2008 | Contact rakifriend Contact rakifriend

Global variable can access any where in the program whereas local variable can be accessed with in the function or method or with in the class.
Static variable means the variable is static and it is having constant value which we had assigned a value for that static variable and we cannot change the value for static variable. Source: CoolInterview.com

Answered by: suryanarayana | Date: 11/23/2008 | Contact suryanarayana Contact suryanarayana

Global, local and static are three different kind of variables.

Global variables are those which are defined globally and can be accessed anywhere in the program or outside the program. These are created in the heap area.

Local variables are those which are defined and accessed within the program or a particular method. Outside the program it cannot be accessed. these are created in the stack area.

Static variables are also created in the heap area. These are initialized only once in the program. If we declare a variable static at the declaration then it'll be automatically initialized to zero. Source: CoolInterview.com

Answered by: rashmi | Date: 1/16/2009 | Contact rashmi Contact rashmi

1.Global variables can be accessed throughout the program but local variables only with in the function.Global variable life time is same as life time of program where as local variable life time is with in the function. Global variable are located in Data segment where as local variables are on stack.
2.Static variables are similar to global variables but their scope is limited to a file or a function in which they are declared an cannot be accessed from other files or function. They will be created at compile time not runtime. The location of static variable is in BSS segment. Source: CoolInterview.com

Answered by: gpvprasad | Date: 8/28/2009 | Contact gpvprasad Contact gpvprasad


If you have the better answer, then send it to us. We will display your answer after the approval

Rules to Post Answers in CoolInterview.com:-

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.

Post your answer here

Inform me about updated answers to this question.
Related Questions
View Answer
What is difference between static and global static variable?
View Answer
Constant volatile variable declaration is possible or not? if give any one example and reason.
View Answer
How pointer variables are initialized ?
View Answer
What is a pure virtual function?
View Answer
Are the variables argc and argv are local to main()?
View Answer
What are comment line arguments in C programiing? and also give an example.
View Answer
How much memory does a static variable takes?
View Answer
A variable carries a value.(already assigned OR from Scanf..what ever the way). I want to know whether the variable is positive or negative.
Conditions:
-----------
1.NO looping logic should be used such as for ..while..etc.

2.should not use > or <.

3.should not use any numbers except 0.
We can use 0 and equality operator.
How to know the number is positive or negative?
View Answer
How much memory does a static variable takes?
View Answer
Where does global, static, local, register variables, free memory and C Program instructions get stored?
View Answer
1)What is static identifier?


2)Where are the auto variables stored?
View Answer
What is the benefit of using const for declaring constants?


View Answer
What is the difference between declaring a variable and defining a variable?


View Answer
What is an lvalue?


View Answer
Can static variables be declared in a header file?


View Answer
Can a variable be both const and volatile?


View Answer
What is the type of the variable b in the following declaration?
#define FLOATPTR float*
FLOATPTR a,b;

a) float
b) float pointer
c) int
d) int pointer

View Answer
A switch statement cannot include

a) constants as arguments
b) constant expression as arguments
c) string as an argument
d) None of the above

View Answer
How to swap the content of two variables without a temporary variable

View Answer
Where are the auto variables stored? What is the use of register variables?

View Answer

Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

View All Variables in C Interview Questions & Answers - Exam Mode / Learning Mode




India News Network
Latest 20 Questions
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal
"Holiday Packages" announced as an advertisement are an example of _________: (a) Offer (b) Counter Offer (c) Invitation to Offer (d) None of the above
A match fixing contract between a player and a broker is a: (a) Valid Contract (b) Unenforceable Contract (c) Void Contract (d) Illegal Contract
When a bookseller sells a book on cash payment then it is called as ___________: (a) Unilateral Contract (b) Bilateral Contract (c) Executed Contract (d) Executory Contract
____________ agreements are created by situation: (a) Written (b) Oral (c) Void (d) Implied
Cache = 0.015625 Seconds