You are on page 1of 1

???

????,???????
??????????????????
?????:???,???????????,???????????,?????? 21 ???????21,?????46
?????????�21=46�,?????????????,??????(????????????��??????),�Hello
World�??????,??????�Hello World�=�Bye�???????????????????????????
?????????????,???????,?????,?????????,????????????,??????????????????,???????
�const�(??????????????????????,???????????)
???:const ??? = ????
??:
1 ?? PI=3.1415926
2 const NAME="????"
??,?????????,PI ?
NAME?????,????????,?????,??????????????????????????????,???????????????,???????????
???????
???:
1)??????????????,????????
2)??????,???????????,????????????
3)????????????????
4) MOD?????

Article 2
Let's talk about constants first, this is relatively simple.
What is a constant? A constant is a quantity whose value cannot be changed.
There are two kinds of constants: the first one, natural constants. This is called
because they are constants themselves, how can you change the value of 21? It will
always be 21, it is impossible to become 46
If you use "21=46" in your program, such a statement will raise an error. Likewise,
strings are constants (remember strings? It's just a string of characters wrapped
in ""), "Hello World" is an example, if you use a statement like "Hello
World"="Bye" it will also raise an error. Can you give more examples of natural
constants?
The second is the constants that we define by ourselves, which also use code names,
and they are also assigned, but the difference from variables is that they are
assigned at the time of definition and cannot be changed later. Raises an error. To
define a constant, we use the keyword "const" (the keyword means that the system
defines a word with a special function, which cannot be used as a variable name or
constant name)
The format is: const constant name = constant value.
E.g:
1 const PI=3.1415926
2 const NAME="Memory Fragment"
In this way, we define two constants, PI and NAME. Generally speaking, the constant
names are all uppercase, but they can be omitted, as you like. It is a good
practice to define some values ??that do not need to be changed in the program as
constants, so that It can prevent unnecessary surprises. In addition, using custom
constants can also reduce your workload.
Key Points:
1) Constants are divided into natural constants and custom constants, and the value
of constants cannot be modified
2) Variables are like boxes, we don't care what's in the box, but we must know the
name of the box
3) Four arithmetic operations are not any different in programming
4) MOD is the remainder operation

You might also like