当前位置:网站首页>Differences between constants and variables (detailed description) (learning note 3 -- variables and constants)
Differences between constants and variables (detailed description) (learning note 3 -- variables and constants)
2022-06-13 01:47:00 【It's Beichen bupiacra】
Preface :
If you are learning C Language without knowing where to start , You can study with me C Language , During the winter vacation, I will post a blog every day , There are all kinds of C The knowledge of language , If you want to learn , Want to improve , Come and punch in with me every day , I hope we can make progress together .
Variables and constants
C Constants and variables in language , First of all, we can clearly see the mutually exclusive relationship between them from the name .“ often ” It means forever , That is to say C A quantity that can remain constant in a language is called a constant , conversely , A variable whose value can change is called a variable .
One 、 Constant
Constants usually appear as values , What we learned before C The basic data types of language , Have constants corresponding to them . in addition , We will also recognize a special string constant .
1. integer constants
C In language , Any integer value is an integer constant , And the integer value can be octal 、 In hexadecimal format . The default integer value is int type , Is the standard integer type .
An integer value 13 All kinds of hexadecimal writing methods
Base number | The way of writing | explain |
---|---|---|
octal | 015 | In numbers 0 As a prefix |
Decimal system | 13 | No prefix is required |
Hexadecimal | 0xD、0XD | In numbers 0 And letters (x or X) As a prefix |
2. Real constant
stay C In language , Any valid value with a decimal point is a real constant , Such as “2.0”, It can also be “.2”, The default real constants are double type .
3. character constants
Enclosing a character in single quotation marks is a character constant ,'a'、'A'、'5'、'\n', These are character constants .
Pay attention to the following three points when using :
1. Single quotation marks cannot be used in Chinese ,‘a’ It's wrong. , 'a' That's right. .
2. A single quotation mark can contain only one character ,'ab' It's wrong. ,'a'、'\n', That's right. “\n” It's only one character , Play the role of line feed , This is called an escape character .
3. Single quotation marks cannot be empty ,'' It's wrong. ,' ' That's right. , Because there is a space character between the following single quotation marks .
Commonly used escape characters :
Escape character | effect |
---|---|
\a | Buzzer alarm |
\r | enter |
\000 | Use three octal digits to represent characters |
\’ | Escape single quotation marks to normal characters |
\\ | Escape backslash to normal character |
\n | Line break |
\t | TAB key ( Horizontal TAB ) |
\x00 | Use two hexadecimal digits to represent characters |
\’’ | Escape double quotation marks to normal characters |
\0 | Null character ( String end flag ) |
4. String constant
stay C In language , There is no such data type as string , But there are string constants .
The contents enclosed in English double brackets are called string constants or short for string , Such as "abc"、"123"、"".
The third one is special , There is nothing in the double quotation marks , But it is an empty string .
There are two points to note when using strings :
1. Double quotation marks must be in English , Chinese double quotation marks are not allowed .
2. Strings cannot be nested , That is, you cannot have another string in one string ,
If you want to use double quotation marks in a string , The escape character is required “\"”.
Two 、 Variable
Constants usually exist as values , The variable looks like a “ Containers ”. Variables of different types are like variables of different sizes “ Containers ”, Data of different types and sizes can be placed inside . A constant is the value itself , Variables usually have names , We call this the variable name . Users can easily access and operate the data placed in variables through variable names .
1. Definition of variables
C The definition format of variables in language :
Type specifier Variable name ;
Points to pay attention to when naming variables :
1. Out of commission C Keywords in the language are used as variable names .
2. Variable names must be alphabetic or underlined “_” start .
3. Variable name cannot be defined repeatedly
4.C Language is case sensitive .
2. Initialization and assignment of variables
“ = ” The assignment operator assigns the value on the right to the variable on the left .
The assignment operation is used to define variables at the same time , It is called variable initialization :
int a = 100;
If you do not assign values when defining variables , It is not the initialization of variables , It is just an ordinary assignment operation :
int a;
a = 100;
边栏推荐
- 一种不带CPU的DPU架构:Hyperion
- Logging system in chromium
- DFS and BFS to solve Treasure Island exploration
- Uuid/guid introduction, generation rules and generation codes
- [official document summary] writing standards for academic dissertations of National University of science and technology
- Compiling minicom-2.7.1 under msys2
- Should the audience choose observation mode or positioning mode?
- Record the VMware installation process of VMware Tools and some problems encountered
- 开发者来稿|AMD赛灵思中文论坛分享 - 提问的智慧
- TensorFlow2的Conv1D, Conv2D,Conv3D机器对应的MaxPooling详解
猜你喜欢
URI, URL and urn difference, relation and syntax diagram
Startup, connection and stop of MySQL service
Use mediapipe+opencv to make a simple virtual keyboard
Establishment of microservice development environment
三、上传织物图片至SQL Server并提供name进行展示织物照片
Implementation of pointer linked list
Qt实现思维导图功能(二)
水管工游戏
服务器安装jupyterlab以及远程登录配置
LabVIEW大型项目开发提高质量的工具
随机推荐
四、入库管理功能的完善
Note: common gadgets in project architecture
[wsl2] restrict wsl2 accessible hardware resources (cpu/ memory)
ng-tv-focusable
PyFlink实现自定义SourceFunction
Jeux de plombiers
Detailed explanation of audience characteristics
Pytoch freeze pre training weights (feature extraction and BN layer)
兴趣相似的受众群体
Unity jsonutility failed to serialize list
Devexpress implementation flow chart
leetcode743. Network latency (medium, Dijkstra)
(no plug-in) summary of vim basic shortcut keys
Numpy multidimensional array transpose transpose
Topic creation and running example of ROS
Matplotlib drawing Chinese garbled code
Cmake has no obvious error after compilation, but prompts that pthread cannot be found
[MathType] use MathType to output latex style formula
The method of drawing rounded panel with Delphi
Server installation jupyterab and remote login configuration