Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Difference between static global and global?

Answers were Sorted based on User's Feedback



Difference between static global and global?..

Answer / rakesh

Static global has file scope and it can't be accessed
outside of the file.
while global has program scope and can be accessed
outside of file in which it has been defined using extern
keyword.

Is This Answer Correct ?    139 Yes 7 No

Difference between static global and global?..

Answer / sandeep gautham

a program can be spread across two or more files...
so, a global variable can be accessed by all the files..
where as, a static global variable can be accessed only by
the file in which it is declared...static means permanent
and hence the value in static global variable is shared by
all the functions in that file...

Is This Answer Correct ?    35 Yes 5 No

Difference between static global and global?..

Answer / saugat biswas

I think all the answers above are restricted to C only.
However if extended to C++, static has a file scope and the
static variable is a variable for the class and not the
instances. In other words, static variables are shared
variables. All the instances of the class actualy use the
same static variable. Static variables and function can
directly be called without creating instances of the class
by using scope resolution operator. Static variables are
not initialized in constructors rather they are initialized
as global variables. Example

Example.h
~~~~~~~~~
class A
{
public:
static int x;
A();
~A();
static int getX(void);
}

Example.cpp
~~~~~~~~~~~
int x = 0;
A() //Contructor
{}

~A() //Destructor
{}

int getX(void)
{
return x;
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Now in class B we can write:

#include "Example.h"
class B
{
int myX = Example::getX();
}

Is This Answer Correct ?    18 Yes 0 No

Difference between static global and global?..

Answer / umasankar

what sandeep said is absolutely correct

Is This Answer Correct ?    16 Yes 4 No

Difference between static global and global?..

Answer / derick

Chitra, "static global is fixed.but global variables are
changed." what does this mean?

Please do not answer like this if you are not sure.

What Rakesh said is true except that Static global
variable's scope is limited to its block.

Is This Answer Correct ?    21 Yes 10 No

Difference between static global and global?..

Answer / rajesh

also static variables has default value as 0.

Is This Answer Correct ?    6 Yes 2 No

Difference between static global and global?..

Answer / derick

Let us make it clear

int x=22;//global

int* function()
{
static int x = 99; // static x in function
return &x;
}

main()
{
{
//static x in block
static int x = 88;

//returns static in block
printf("\nvalue: %d", x++);

// static x in function
int *p = function();
printf("\nvalue from function: %d", *p);

// change static x in function
*p = 77;

printf("\nvalue from function: %d", *p);
// new value of static x declared in function
}
// returns global x
printf("\nvalue: %d", x);

//still static x declared in function is alive in memory
//but cannot be accessed directly as X since the scope of
//x declared in function is limited to the boundary of
//the function
printf("\nvalue from function: %d", *function());
}

Is This Answer Correct ?    7 Yes 4 No

Difference between static global and global?..

Answer / veera

hello Sheela u r question is good, but u can access global
static through extern key word in other file,it take the
value but we can,t change the value in that file.

But in case of global variable it's possible to change
the value in other file.

Is This Answer Correct ?    1 Yes 0 No

Difference between static global and global?..

Answer / ravi.g

local static variable and global variable both are same
since both can be accessed from all the functions in the
same file in which they declared.

Global variable has the file scope since it can be accessed
from other files also by using extern keyword.

Local static vaeriables have no file scope since they can
not be accessed from other files by any means.

Is This Answer Correct ?    2 Yes 2 No

Difference between static global and global?..

Answer / ravi.g

global static variables have no file scope since they can
not be accessed from other files by using extern keyword

Global variables have the file scope since they can be
accessed from other files using extern keyword

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C++ General Interview Questions

Explain how would you handle a situation where you cannot call the destructor of a local explicitly?

0 Answers  


How is memory managed in C++?

2 Answers  


Explain about Garbage Collector?

0 Answers  


What is a block in c++?

0 Answers  


What is a wchar_t in c++?

0 Answers  


Give an example of run-time polymorphism/virtual functions.

0 Answers  


Suppose that data is an array of 1000 integers. Write a single function call that will sort the 100 elements data [222] through data [321].

0 Answers  


What are dynamic type checking?

0 Answers  


Why cstdlib is used in c++?

0 Answers  


what is data Abstraction

2 Answers  


What is difference between shallow copy and deep copy? Which is default?

1 Answers  


Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.

0 Answers  


Categories