Are static local variables stored in the class between objects?

class MyClass
{
  static int staticInt;

  void instanceMethod( int param )
  {
    static int parameter = param;
  }
}

It is clear that it staticIntis shared between all instances of MyClass. But can different instances of MyClass have different values ​​of a parameterstatic local variable in instaceMethod?

Update

What is between the programs? Of course, they can be different in several copies of the program? What defines the "area" there - the executive unit? C ++ runtime?

Update

Thanks - it helped me crush a critical error. I wish I could accept all of them, but I'm going with the first answer without any other criteria.

+3
source share
4 answers

parameter.

parameter , - .

+7

parameter , parameter .

parameter. static . , , - . , . - . , "" , , .

parameter staticInt, . , staticInt , parameter instanceMethod.

, . .

+6

Yes, they both persist. They cannot have different meanings between instances.

+1
source

values ​​are not saved during program execution (between two different calls of the same program)

0
source

Source: https://habr.com/ru/post/1749445/


All Articles