.net预定义的数学常量_C常量和定义预处理器
.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]
翻译自: https://www.poftut.com/c-constants-define-preprocessor/
.net预定义的数学常量
上一篇: python:整数在二进制、八进制、十进制和十六进制之间转换
下一篇: 算法训练 二进制转十进制