How are local and global variables initialized by default?

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

    Just for the sake of completeness if you had references:

    References must be initialized on declaration, otherwise you get punished by a compiler error. This means a reference always needs another value or reference it refers to (like the says), this is ensured by the compiler so you cannot forget it. This also implies that references can never be null pointers. However the object they refer to might become invalid.

提交回复
热议问题