+ 5
What is the output of this line?can we change static variable value ?if yes ,y it is said static?why to use static keyword?
static int a=7; a=11; cout<<++a;
6 Réponses
+ 2
Output will be 12
Yes, values of the static variables can be changed.
It is said static because only 1 copy or the original copy of a static variable is shared by all objects using it, whereas for non-static variables each object have its own copy of that variable.
As only a single copy of static variable is shared among the objects so if 1 objects modifies the value of the static variable then the value is modified for all objects using that static variable, this is the reason we use static variable; i.e. to maintain concurrency in data.
0
First, please give us detailed information about your problem, for example here misses the programming language. Due to your problem we can solve this even without this information. Static is a modifier for object orientated programming. It has nothing to do with access in your example.
For explaining static, we first start with a class. When you write a class object and insert there a static variable "staticx", a normal variable "x", a static method "staticFunc" and a normal method "func". Now staticx and staticFunc are class owned stuf, which means you can access them without instantiating an object of the class. In opposte to that you need to instantiate an object of the class to access x and func.
0
dude its clear that this is c++. It should be a hint to give more detailed information next time.
0
error hoga may be
0
ya fir 12 hona chachiye
0
A static variable works almost same as global variable.The difference is it's scope is only limited in that file and you can declare it in a function