How are local and global variables initialized by default?

后端 未结 10 1701
粉色の甜心
粉色の甜心 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:03

    global_A reference is initialized to null.

    No, its a valid object (constructed based on default constructor, which you don't have in your code but compiler adds that)

    global_int is 0

    yes

    local_A reference is null

    no, same reason as for global

    local_int is uninitialized

    no, its initialized to 0

    Both global_A.x and local_A.x is uninitialized.

    no both are initialized to 0

提交回复
热议问题