How are local and global variables initialized by default?

后端 未结 10 1694
粉色の甜心
粉色の甜心 2020-11-30 10:39

Based on below, am i right?

  • global_A reference is initialized to null.
  • global_int is 0
  • local_A reference is null
  • local_int is uninit
10条回答
  •  孤城傲影
    2020-11-30 11:02

    There are no references in your code, so any of your points that mention "references" make no sense.

    In your example, both global object - global_int and global_A - are zero-initialized. Both local objects - local_int and local_A - contain indeterminate values, which means that local_int and local_A.x are not initialized.

    P.S. Of course, as other already noted, your code is non-compilable. You can't declare A objects before declaring class A (and you are missing a ; after the class definition).

提交回复
热议问题