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
Write down the equivalent pointer expression for referring the same element a[i][j][k][l]?
Does c++ support multilevel and multiple inheritances?
Is c# written in c++?
What are multiple inheritances (virtual inheritance)?
A mXn matrix is given and rows and column are sorted as shown below.Write a function that search a desired entered no in the matrix .with minimum complexity 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
What is split a string in c++?
How do you decide which integer type to use?
an operation between an integer and real always yeilds a) integer result b) real result c) float result
What is the difference between containment and delegation?
Can comments be nested?
What is data type in c++?
If a base class is an adt, and it has three pure virtual functions, how many of these functions must be overridden in its derived classes?
Which is not a valid keyword a) public b) protected c) guarded
List the merits and demerits of declaring a nested class in C++?
What is late binding c++?