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                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C++  >>  C++ General
 
 


 

 
 STL interview questions  STL Interview Questions
 OOPS interview questions  OOPS Interview Questions
 C++ General interview questions  C++ General Interview Questions
Question
Difference between static global and global?
 Question Submitted By :: Shalini
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Difference between static global and global?
Answer
# 1
there is no any diffrence between static and non static 
global variable
 
Is This Answer Correct ?    1 Yes 8 No
Afroz
 
  Re: Difference between static global and global?
Answer
# 2
static means fixed we should not change anything,but in non 
static we can change.
 
Is This Answer Correct ?    1 Yes 6 No
Priya
 
 
 
  Re: Difference between static global and global?
Answer
# 3
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 ?    9 Yes 0 No
Rakesh
 
  Re: Difference between static global and global?
Answer
# 4
static global is fixed.but global variables are changed.
 
Is This Answer Correct ?    1 Yes 4 No
Chitra
 
  Re: Difference between static global and global?
Answer
# 5
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 ?    0 Yes 1 No
Derick
 
  Re: Difference between static global and global?
Answer
# 6
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 ?    1 Yes 0 No
Derick
 
  Re: Difference between static global and global?
Answer
# 7
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 ?    3 Yes 1 No
Sandeep Gautham
 
  Re: Difference between static global and global?
Answer
# 8
what sandeep said is absolutely correct
 
Is This Answer Correct ?    2 Yes 0 No
Umasankar
 

 
 
 
Other C++ General Interview Questions
 
  Question Asked @ Answers
 
difference between c and c++? Infosys8
How to reduce a final size of executable?  1
Which algorithm do you like the most? Why? Google1
What is "mutable" keyword?  2
How is an Abstract Base Class(ABC) related to an "Abstract Data Type" (ADT)  2
If P is the population on the first day of the year, B is the birth rate, and D is the death rate, the estimated population at the end of the year is given by the formula: The population growth rate is given by the formula: B – D Write a program that prompts the user to enter the starting population, birth and death rates, and n, the number of years. The program should then calculate and print the estimated population after n years. Your program must have at least the following functions: 1. growthRate: This function takes its parameters the birth and death rates, and it returns the population growth rate. 2. estimatedPopulation: This function takes its parameters the current population, population growth rate, and n, the number of years. It returns the estimated population after n years Your program should not accept a negative birth rate, negative death rate, or a population less than 2.  1
what is an array  12
Explain the difference between 'operator new' and the 'new' operator? Lucent1
What is the difference between = and == in C? Intel8
Why is it difficult to store linked list in an array? Lucent2
How many bit combinations are there in a byte? Intel7
Shall we use 'free' to free memory assigned by new, What are the further consequences?? Symphony4
What is Pure Virtual Function? Why and when it is used ? Lucent4
What C++ libraries are you proficient with? Google1
wrong statement about c++ a)code removably b)encapsulation of data and code c)program easy maintenance d)program runs faster  8
What is the Diffrence between a "assignment operator" and a "copy constructor"? Wipro2
how to swap two strings without using any third variable ?  3
How the V-Table mechanism works? HP3
Evaluate: int fn(int v) { if(v==1 || v==0) return 1; if(v%2==0) return fn(v/2)+2; else return fn(v-1)+3; } for fn(7); a) 10 b) 11 c) 1 Quark1
Difference between Top down and bottom up approaches for a given project ? HP1
 
For more C++ General 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