.net预定义的数学常量_C常量和定义预处理器

.net预定义的数学常量

.net预定义的数学常量

[rps-include post=6557]

[rps-include post = 6557]

Up to now we have worked with variables. As its names states variables values may change in the flow of application. Variables changes by adding, removing, subtracting etc. This may be ideal solution for most of time but how can we avoid it if we need constant values. Because if we want to define Pi number and do not want to change it as Pi is fixed number in mathematics. Here the solution is making them explicitly constant.

到目前为止,我们已经使用了变量。 顾名思义,变量值可能会在应用程序流程中发生变化。 变量通过加,减,减等来改变。这在大多数情况下可能是理想的解决方案,但是如果我们需要恒定值,如何避免这种情况。 因为如果我们要定义Pi号并且不想更改它,因为Pi在数学中是固定数。 这里的解决方案是使它们显式恒定。

不变 (Constant)

To make variables constant const variable is used. By adding const keyword before variable type the variable becomes a constant and can not be changed.

使变量常量const 使用变量。 通过添加const 变量类型之前的关键字变量变为常量且无法更改。

const float PI=3.14;

Not just numbers also other variable types can be made constant

不只是数字,还可以使其他变量类型恒定

字符串常量(String Constant)

Here string poftut.com is string constant and can not be change during execution of the application.

这里的字符串poftut.com是字符串常量,在应用程序执行期间不能更改。

const char site[]="poftut.com"

#define (#define)

Define preprocessor provides another way to define constant. This way definition do not need a variable type. #define simple puts value all occurrences of identifier

定义预处理器提供了另一种定义常量的方式。 这种方式的定义不需要变量类型。 #define simple puts赋予所有出现的标识符值

#define IDENTIFIER VALUE

Here is an example usage of #define

这是#define的示例用法

#include <stdio.h> 
#define PI 3.14 
 
int main(){ 
 
        printf("PI"); 
 
        return 0; 
}

[rps-include post=6557]

[rps-include post = 6557]

LEARN MORE  Python Variables and Types
了解更多Python变量和类型

翻译自: https://www.poftut.com/c-constants-define-preprocessor/

.net预定义的数学常量

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值