How would you set a variable to the largest number possible in C?

前端 未结 10 620
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-01 17:53

How would you set a variable to equal infinity (or any guaranteed largest number value) in C?

10条回答
  •  無奈伤痛
    2020-12-01 18:40

    I generally use the *_MAX macros found in limits.h INT_MAX for integers etc. These will always be correctly set for the variable type. Even the explicitly sized types such as uint32 will have corresponding entries in this header file.

    This has the virtue of being the largest possible value that a variable of that type can hold.

    For an unsigned integer as you asked for in your question, you would use UINT_MAX

提交回复
热议问题