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

What will i and j equal after the code below is executed? Explain your answer.

1 Answers  


Why c++ is so important?

0 Answers  


Explain linear search.

0 Answers  


Write a corrected statement in c++ so that the statement will work properly. if (4 < x < 11) y=2*x;

0 Answers  


Is it possible for a member function to delete the pointer, named this?

0 Answers  


Differentiate between a deep copy and a shallow copy?

1 Answers  


What are the advantage of using register variables?

0 Answers  


what is difference between internet and Internet?

12 Answers   College School Exams Tests, Microsoft, MIT, TCS,


Does c++ have string data type?

0 Answers  


What is ofstream c++?

0 Answers  


Write a c++ code that will calculate the roots of a quadratic equation a2+ bx+c=0 Hint: d = sqrt (b2-4ac), and the roots are: x1 = (€“b + d)/2a and x2 = (€“b €“ d)/2a (use sqrt function from cmath.h )?

0 Answers   Maxobiz,


How do you initialize a class member, class x { const int i; };

8 Answers   emc2,


Categories