How to default-initialize local variables of built-in types in C++?

后端 未结 5 754
春和景丽
春和景丽 2021-01-06 20:34

How do I default-initialize a local variable of primitive type in C++? For example if a have a typedef:

typedef unsigned char boolean;//that\'s Microsoft RPC         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-06 21:20

    If I understand the original question, the poster is saying he wants variables of a given type to always have the same initial value, but he doesn't care what that value is, because he'll never look at it. Am I right?

    If so, then my question for the poster is this: If you did not initialize the variables they would have random initial values... but you said you never look at initial values - so why does it matter if they're random?

    I think the key question is - what are you trying to achieve here?

提交回复
热议问题