ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
how can we use static and extern?and where can we use this?
 Question Submitted By :: Manojkumar
I also faced this Question!!     Rank Answer Posted By  
 
  Re: how can we use static and extern?and where can we use this?
Answer
# 1
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 ?    2 Yes 3 No
Vignesh1988i
 
  Re: how can we use static and extern?and where can we use this?
Answer
# 2
the above answer is write.thanks to vignesh.
 
Is This Answer Correct ?    0 Yes 0 No
Manojkumar
 
 
 
  Re: how can we use static and extern?and where can we use this?
Answer
# 3
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 ?    0 Yes 0 No
Pramod
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
what is dangling pointer? LG-Soft1
what does the following function print? func(int i) { if(i%2)return 0; eale return 1; } main() { int =3; i=func(i); i=func(i); printf("%d",i);} TCS8
HOW TO ANSWER IF ASKED " WHAT KIND OF A PERSON ARE YOU?" I NEED AN ANSWER THAT IMPRESS THE INTERVIEWER  2
main() { int a = 65; printf(“%d %o %x”,a,a,a); } Output 65 101 41 Please explain me.How it is coming like that? Excel2
52.write a “Hello World” program in “c” without using a semicolon? 53.Give a method to count the number of ones in a 32 bit number? 54.write a program that print itself even if the source file is deleted? 55.Given an unsigned integer, find if the number is power of 2?  6
What are data breakpoints? Adobe1
what is the difference between. system call and library function? CDAC2
two variables are added answer is stored on not for third variable how it is possible?  3
Is there any restriction in how many arguments printf or scanf function can take? in which file in my c++ compiler i can see the code for implementation of these two functions??  3
what is difference b/w extern & volatile variable?? Teleca2
what are the interview question's in the language c Nipuna1
suppose we use switch statement and we intilize years name using enum statement like(jan,feb,mar,------dec) we take integer value as an input .question is that the month which we analyz is from 0 to 11 bt if i enter 12 than how he again starts from begning and print jan  1
Is reference used in C?  1
In the following control structure which is faster? 1.Switch 2.If-else and which consumes more memory?  4
prototype of sine function. Cadence2
Why the use of alloca() is discouraged? Oracle2
write a recursive program in'c'to find whether a given five digit number is a palindrome or not  1
What is true about the following C Functions a.Need not return any value b.Should always return an integer c.Should always return a float d.Should always return more than one value. TCS7
print the following using nested for loop. 5 4 3 2 1 1 2 3 4 3 2 1 1 2 1 2 1 1 2 3 4 3 2 1 1 2 3 4 5  5
what r callback function?  1
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com