当前位置:网站首页>Day 6 of learning C language
Day 6 of learning C language
2022-07-27 09:16:00 【ruin987】
free
1. Give the space back to " System "
2. You can only return the first address of the requested space
character string
With 0( Integers 0) A string of characters at the end
0huo"\0" It's the same , But and '0' Different
0 Marks the end of the string , But it is not a part of the string. When calculating the length of the string, it does not include this 0
String exists as an array , Access as an array or pointer
More in the form of pointers
string.h There are many functions to handle strings in
C Language strings exist in the form of character arrays
You cannot operate on a string with an operator
You can also traverse strings through arrays
The only special thing is that string facets can be used to initialize character arrays
And the standard library provides a series of string functions
String constant
"Hello" It will be turned into an array of characters by the compiler and placed somewhere , The length of this array is 6, At the end, there is also a sign of the end 0
Two adjacent string constants are automatically concatenated
String constant
char*s="Hello,world!";
s It's a pointer , Initialize to point to a character constant
Because of where this constant is , So actually s yes const char*s, But for historical reasons , The compiler accepts without const Writing
But try to s Writing the indicated string will lead to serious consequences
If you need to modify the string , You should use arrays : char s [] = " Hello,world! ";
char* Is string ?
The string can be char* In the form of
char* Not necessarily a string
The original meaning is a pointer to a character , It may point to an array of characters ( It's like int* equally )
Only the character array it refers to has an ending 0, To say that it refers to a string
getchar
int getchar(void);
Read in a character from standard input
The return type is int To return to EOF(-1)
Windows-->Ctrl-Z
Unix-->Ctrl-D
strlen
size_tstrlen(const char *s);
return s String length of ( Not including the ending 0)
strcpy
char*strcpy(char*restrict dst,const char*restrictsrc);
hold src Copy the string of to dst
restrict indicate src and dst No overlap (C99)
return dst
In order to chain the code
strcat
char*strcat(char*restrict s1,const char*restricts2);
hold s2 copy to s1 Behind , Take a long string
return s1
s1 There must be enough space
The form of the declaration structure
struct point{
int x;
inty;
};
struct point p1,p2;
p1 and p2 All are point There are x and y Value
struct{
int x;
int y;
}p1,p2;
p1 and p2 It's all a nameless structure , There are x and y
struct point{
int x;
int y;
}p1,p2;
p1 and p2 All are point There are x and y Value t
For the first and third forms , All declare structures point. But the second form does not declare point, Only two variables are defined
Structural operations
To access the whole structure , Use the name of the structure variable directly
For the whole structure , It can be assigned Address fetch , It can also be passed to function parameters
p1=(struct point){5,10}; // amount to p1,x=5;p1 . y=10;
p1=p2; // amount to p1 . x=p2.x;p1.y=p2.y;
Typedef
typedef long int64_t;
long yes ( The original type )
int64_t yes ( New type )
Global variables
Variables defined outside functions are global variables
Global variables have global lifetime and scope
They have nothing to do with any function
They can be used inside any function
Global variable initialization
Global variables that are not initialized will get 0 value
The pointer will get NULL value
Global variables can only be initialized with values known at compile time
Their initialization takes place in main Function before
Hidden global variables
If there is a variable with the same name as the global variable inside the function , Then the global variable is hidden
Static local variables
Add... When defining local variables static The modifier becomes a static local variable
When the function leaves , Static local variables continue to exist and keep their values
The initialization of static local variables will only be done when entering this function for the first time , In the future, when entering the function, it will keep the value of the last time it left
Static local variables are actually special global variables
They are in the same memory area
Static local variables have a global lifetime , Local scope within a function
static Here, it means local scope ( Locally accessible )
边栏推荐
- Data interaction based on restful pages
- Specific methods and steps for Rockwell AB PLC to establish communication with PLC through rslinx classic
- Nut joke based on arkui ETS
- Easy language programming: allow the screen reading software to obtain the text of the label control
- Size limit display of pictures
- Restful
- CUDA programming-05: flows and events
- async/await的执行顺序以及宏任务和微任务
- ArkUI开发框架组件的生命周期
- [daily algorithm 94] classic interview question: motion range of robot
猜你喜欢

CUDA programming-04: CUDA memory model

pollFirst(),pollLast(),peekFirst(),peekLast()

Explanation of common basic controls for C # form application (suitable for Mengxin)

08_ Service fusing hystrix

Antdesign a-modal user-defined instruction realizes dragging and zooming in and out

Music experience ceiling! Emotional design details of 14 Netease cloud music

The execution sequence of async/await, macro tasks and micro tasks
![[C language - zero foundation lesson 6] input and output sentence format and compound sentence](/img/d5/b9935a37b634db7f5740779009e44f.png)
[C language - zero foundation lesson 6] input and output sentence format and compound sentence

Hard core structure, violent interpretation

Specific methods and steps for Rockwell AB PLC to establish communication with PLC through rslinx classic
随机推荐
Antdesign a-modal自定义指令实现拖拽放大缩小
[C language - zero foundation lesson 14] variable scope and storage class
[C language - zero foundation lesson 8] circular structure and break continue
[micro service ~sentinel] sentinel dashboard control panel
软件测试功能测试全套常见面试题【功能测试-零基础】必备4-1
巴比特 | 元宇宙每日必读:广州南沙发布“元宇宙九条”措施,平台最高可获得2亿元资金支持...
二叉树讲解
npm install报错 强制安装
一些实用、常用、效率越来越高的 Kubernetes 别名
Apple cut its price by 600 yuan, which was almost a devastating blow to the collapse of its domestic flagship mobile phone
Tensorflow package tf.keras module construction and training deep learning model
Specific methods and steps for Rockwell AB PLC to establish communication with PLC through rslinx classic
[cloud native kubernetes practice] deploy the rainbow platform under the kubernetes cluster
网易笔试之解救小易——曼哈顿距离的典型应用
Deep understanding of Kalman filter (2): one dimensional Kalman filter
被三星和台积电挤压的Intel终放下身段,为中国芯片定制芯片工艺
[C language - zero foundation lesson 13] the mystery of string
Tensorflow loss function
CUDA programming-01: build CUDA Programming Environment
Restful