c++ 常数乘以矩阵
In the last post I introduced variables in C.
在上一篇文章中,我介绍了C语言中的变量 。
In this post I want to tell you everything about constants in C.
在这篇文章中,我想告诉您有关C常量的所有信息。
A constant is declared similarly to variables, except it is prepended with the const
keyword, and you always need to specify a value.
常量的声明与变量的声明类似,不同之处在于const
带有const
关键字,并且您始终需要指定一个值。
Like this:
像这样:
const int age = 37;
This is perfectly valid C, although it is common to declare constants uppercase, like this:
这是完全有效的C语言,尽管通常将常量声明为大写,如下所示:
const int AGE = 37;
It’s just a convention, but one that can greatly help you while reading or writing a C program as it improves readability. Uppercase name means constant, lowercase name means variable.
这只是一个约定,但是可以提高您的可读性,因此在读或写C程序时可以极大地帮助您。 大写名称表示常量,小写名称表示变量。
A constant name follows the same rules for variable names: can contain any uppercase or lowercase letter, can contain digits and the underscore character, but it can’t start with a digit. AGE
and Age10
are valid variable names, 1AGE
is not.
常量名称遵循与变量名称相同的规则:可以包含任何大写或小写字母,可以包含数字和下划线字符,但不能以数字开头。 AGE
和Age10
是有效的变量名, 1AGE
不是。
Another way to define constants is by using this syntax:
定义常量的另一种方法是使用以下语法:
#define AGE 37
In this case, you don’t need to add a type, and you don’t also need the =
equal sign, and you omit the semicolon at the end.
在这种情况下,您不需要添加类型,也不需要=
等号,并且最后省略了分号。
The C compiler will infer the type from the value specified, at compile time.
C编译器将在编译时根据指定的值推断类型。
c++ 常数乘以矩阵