Should Local Variable Initialisation Be Mandatory?

前端 未结 17 2455
忘掉有多难
忘掉有多难 2021-02-14 01:26

The maintenance problems that uninitialised locals cause (particularly pointers) will be obvious to anyone who has done a bit of c/c++ maintenance or enhancement, but I still se

17条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-14 02:05

    Yes: always initialize your variables unless you have a very good reason not to. If my code doesn't require a particular initial value, I'll often initialize a variable to a value that will guarantee a blatant error if the code that follows is broken.

提交回复
热议问题