当前位置:网站首页>C language constant, string, escape character, initial level of annotation
C language constant, string, escape character, initial level of annotation
2022-04-22 03:13:00 【Hair is not as much as code】
List item
Constant
***> C There are several constants in the language
Literal constants : Integer constant 、 Floating-Point Literals 、 character constants , Or string literals such as :123,‘w’,Abc etc.
const Modified constant variable
#define The defined identifier constant
Enumeration constants ***
const Modify the constant

const Before finishing ,a The value of can be changed .

const After retouching ,a The value of can no longer change
So const The modifier is a constant variable , That is, the variable is essentially a variable , however const Gives it a constant property
#define The defined identifier constant

We usually #define The following constant name is set to uppercase ( It's a habit ), Of course, it can also be set to lowercase letters, etc
#define Not only can you define numeric constants , You can also define characters , String and other constants .

Enumeration constants
Enumeration constant format

enum A // Equivalent to a type
{
BOY,
GIRL
}; // Note that you don't have to... In braces ; Comma , After the curly braces, use ;
int main()
{
enum A c = GIRL; // enum A Equivalent to a variable type , here c The value range of can only be in braces BOY or GIRL
return 0;
}
character string + Escape character + notes
character string
stay C In language, double quotation marks "" What is referenced is called a string , Such as :“abcdef”, A... Is hidden at the end of the string \0 As the end of the string , But this is not counted as the content of the string
\0 The role of

We can see arr There are double quotes in the array , That is to say \0, and arr1 There are no double quotes in the array ,arr The printed value of the array is normal ,arr1 The array prints out ab It's worth more after , This is because \0 Is the end of string flag , When printf encounter \0 after , End to perform , and arr1 No, \0, So when he finished printing ab after , It will continue to hit , Know to meet \0 until
Escape character
Some letters are defined in and preceded by "" To show the common things that can't be shown ASCII character , Such as \0,\t,\n etc. , It's called an escape character , Because of the following characters , It's not the original ASCII The character means
Columns such as : We print on the computer \test
We will find that t Be missing ,est There are many spaces in front
This is because in the C When in language \ Followed by t formation \t when , It will become another meaning , We put this \ Characters that, together with other characters, will become another expression are called escape characters
| Escape character | meaning |
|---|---|
| ? | Use... When writing multiple consecutive question marks , Prevent them from being parsed into three letter words |
| ’ | Used to represent character constants ’ |
| \“ | Double quotation marks used to represent the inside of a string |
| \ | Used to indicate a backslash , Prevent it from being interpreted as an escape sequence character . |
| \a | Warning characters , Beep |
| \b | Back space |
| \f | Paper in |
| \n | Line break |
| \r | enter |
| \t | Horizontal tabs |
| \v | Vertical tabs |
| \ddd | ddd Express 1~3 Eight octal numbers . Such as : \130 X |
| \xdd | dd Express 2 Hexadecimal numbers . Such as : \x30 0 |
| Particular attention :8 Cannot appear in hexadecimal 8,16 Cannot appear in hexadecimal 16 | |
![]() |
|
| \628 Originally meet \ddd Escape character ,ddd It means 1-3 Brother 8 Decimal digit , But here comes 8, therefore \62 Is a character ,8 Single character , No longer \628 As a character |
The use of annotations
notes : Screen out some unnecessary code , Or explain some special code

We can use \ Comment on a line of code or add corresponding explanation after this line of code .

** We can also use "/“ As the beginning ”/" As a conclusion, comment on many lines of code **
stay VS In the compiler, we can use the key indicated by the red arrow to comment , The key indicated by the blue arrow cancels the comment .

Select statement
Here we use if else Statement to illustrate

Loop statement
C In language while sentence for sentence
do…while sentence
Here we use while Statement to illustrate

function
Just like the function in our mathematics , When you enter a value into it , It will be executed according to the rules of the function , And get the corresponding result

This is a simple addition function , After entering any two values , This function will follow the rules of its internal addition , Operate on these two numbers , And get the corresponding result .
Array
When we want to store a long string of characters ,C The language specifies that arrays should be used to store .
int arr[10]={
1,2,3,4,5,6,7,8,9,10};// Define an integer array , Inside 10 Brother element
stay C In language , The array has the following table

Array name arr hinder [] The size of the array can be set in ,[] The number inside must be a constant ,

[] The value in cannot be a constant variable , Because the essence of a constant variable is a variable

Must be constant

Use of arrays
#include <stdio.h>
int main()
{
int i = 0;
int arr[10] = {
1,2,3,4,5,6,7,8,9,10};
for(i=0; i<10; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}
版权声明
本文为[Hair is not as much as code]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211352336224.html
边栏推荐
- 收藏的技巧链接
- Saas.数据隔离持久化方案
- [7:00 pm tonight] discussion on the development and application scenarios of metartc
- Sword finger offer special breakthrough version 93, longest Fibonacci series
- 【Laravel系列4.7】连接redis以及缓存应用
- 第9章 内核同步介绍
- 网络和多媒体知识(3)
- Evolution and construction of data warehouse architecture
- Can Chrome browser + postman do interface testing like this?
- Ros2 learning notes (V) -- Summary of common instructions for ros2 command line operation (I)
猜你喜欢
![[7:00 pm tonight] discussion on the development and application scenarios of metartc](/img/58/965e9bd295e34c4b37cd00aada2120.jpg)
[7:00 pm tonight] discussion on the development and application scenarios of metartc
![[BJDCTF2020]Cookie is so stable(漏洞原理详解)](/img/ef/e05de7a94dc9c2398d714cbf30c4ec.png)
[BJDCTF2020]Cookie is so stable(漏洞原理详解)

72. 编辑距离

leetcode:297. 二叉树的序列化与反序列化

Interpretation of Flink's new features of fine-grained resource management

TestNG learning notes

苹果表主题图片爬取!

嘉戎技术深交所上市破发:公司市值41亿 应收账款2.8亿

500 error, unable to forward after submitting the response

微信JSAPI支付方式与错误(当前页面的URL未注册,支付验证签名失败)
随机推荐
go语言实战-----31-----流媒体架构设计之直播架构、音视频通话(常见 流媒体协议 解释)
JS表格排序
7、Request_ Response
[wustctf2020] plain
外包干了四年,废了
Stackoverflow:IActionContextAccessor Is Null
Go language practice ------ 31 ------ live broadcast architecture and audio and video call of streaming media architecture design (common streaming media protocol interpretation)
Protocole d'authentification Kerberos
Apple watch theme picture crawl!
Saas. Data isolation and persistence scheme
Exercise 23, pilot brothers [binary enumeration / bit operation]
二十八.内置模块
二十五.模块/内置模块/模块的安装
Redis event driven framework (Part 1): when to use select, poll and epoll?
网络和多媒体知识(3)
First glimpse of the pytest framework, weak foundation can easily hold
tetracosa-. Deep and shallow copies of classes
Serviceworker cache and HTTP cache
内置函数123
Introduction of explanatory variables in code refactoring

