Difference between static global and global?
Answer Posted / 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 |
Post New Answer View All Answers
What is the basic concept of c++?
What is a wchar_t in c++?
How the programmer of a class should decide whether to declare member function or a friend function?
Difference between pointer to constant vs. Pointer constant
When to use “const” reference arguments in a function?
How does java differ from c and c++?
What is polymorphism in c++? Explain with an example?
Explain how overloading takes place in c++?
What is bubble sort c++?
What do you mean by stack unwinding in c++?
List down the guideline that should be followed while using friend function.
What is meant by a delegate?
Perform addition, multiplication, subtraction of 2-D array using Operator Overloading.
what do you mean by volatile variable?
Can union be self referenced?