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...


how can we use static and extern?and where can we use this?

Answers were Sorted based on User's Feedback



how can we use static and extern?and where can we use this?..

Answer / pramod

static storage class is used for the following situations
1) the variable is defined as static within a function and
we can call the function several times, but we want that the
function should initialize the variable only once that is
during the first call to that function.So the variable will
stay alive in different calls to this function
2)In C++ , if we want a common variable between all the
objects( like a counter for how many objects have been
created) then static is allocated as it is not attached to
any object but class

extern storage is for global variables
1)if we want one varibale to be available to all the
functions in our program, make the varibale as global
variable( extern storage), it will be accessed by all the
functions in that file.But avoid declaring variable as
global for security reasons( can be accessed from any other
file in the PATH) and memory reasons (global variables are
deallocated only when the entire program terminates).
2)if we declare a variable in a file as extern , then
compiler will assume that this variable is not defined in
the present file but in some other file.So while compiling
there won't bw any error but error will come at the linking
if the extern variable is not present in the refernced files.

There is one special case
static global variable

we want a variable to be global , means accessible to all
the functions in that file and want that the variable should
not be accessible to any other file, just to make it static
global variable.So the visibility of that variable becomes
file specific only.

Is This Answer Correct ?    3 Yes 1 No

how can we use static and extern?and where can we use this?..

Answer / manojkumar

the above answer is write.thanks to vignesh.

Is This Answer Correct ?    1 Yes 0 No

how can we use static and extern?and where can we use this?..

Answer / vignesh1988i

static and extern are some types of storage classes in C...
there are four types of storage classes in C:
1) automatic (auto) storage class
2) static storage class
3) register storage class
4) extern storage class

static is a one which will be read only once by the compiler
(ie) it will ignore an another pass.... or it will be
initialized only once....... the scope of this class is
within the block only....

extern is a global declaration , but most of the compilers
dont prefer it to be used within a program.......


thank u

Is This Answer Correct ?    3 Yes 3 No

Post New Answer

More C Interview Questions

class foo { public: static int func(const char*& p) const; }; This is illegal, why?

8 Answers   Google,


change to postfix a/(b+c*d-e)

8 Answers   Value Labs,


how can i print "hello".please consider inverted commas as well.i want to print on console: "hello"

4 Answers   Wipro,


what is the output for the code : main() { int i,j; printf("%d %d ",scanf("%d%d",&i,&j)); }

20 Answers   Infosys,


write a programe returns the number of times the character appears in the string

2 Answers  


what is the use of bitfields & where do we use them?

2 Answers  


is forign key will be unique key any table or not?

2 Answers  


What are the benefits of organizational structure?

0 Answers  


Write a C program to print 1 2 3 ... 100 without using loops?

15 Answers   Hindalco,


Differentiate between a for loop and a while loop? What are it uses?

0 Answers   TISL,


why i join syntel?

23 Answers   ABC, Syntel, TCS,


what is d pitfalls of registers variables

3 Answers   TCS,


Categories