当前位置:网站首页>C language learning log 1.17
C language learning log 1.17
2022-06-13 04:57:00 【Today is also a day without baldness】
Dynamic distributed memory :
malloc function : Call... Before using this function “stdlib” This library , The format is : void*malloc(size_t size); The return type is void.
towards malloc The size of the space requested is in bytes , The result is void*, The required type is converted to the required type ; (int*)malloc(n*sizeof(int)).
TIPS: malloc The amount of memory allocated is limited , When the allocation fails, an empty address or NULL, We can write a code to determine how much memory our computer can allocate .
int mallocSize()
{
void *p;
int cnt = 0;
while((p = malloc(100*1024*1024)))
{
cnt++;
}
printf(" Successfully assigned %d00MB Space ",cnt);
free(p);
return 0;
}
free function :free() It is used to return the space obtained from the application to “ System ”, Applied space , In the end, it should be returned , And you can only return the first address of the requested space .(1. Applied for memory , Be sure to free, Otherwise, the memory will gradually decrease after long-time operation , When there is not enough memory , The system will automatically clear all memory .2.free After that, you can't free The same thing )
String manipulation :
getchar Represents reading in a character ,putchar Represents the output of a character .getchar The usage of is to use directly when entering getchar() Function to get the character ,putchar The usage of is to pass in character variables for printing .
getchar Implemented by macro :#define getchar() getc(stdin).getchar There is one int The return value of type , When the program calls getchar when , The program is waiting for the user to press the button . The characters entered by the user are stored in the keyboard buffer , Until the user presses enter ( The carriage return character is also placed in the buffer ). When the user types enter ,getchar Just started from stdio One character at a time in the stream .getchar The return value of the function is the number of characters entered by the user ASCII code , If the end of the file (End-Of-File) Then return to -1(EOF), And the characters entered by the user will be displayed back to the screen .
Such as : The user entered more than one character before pressing enter , Other characters will remain in the keyboard cache , Waiting for follow-up getchar Call read . in other words , Follow up getchar The call does not wait for the user to press the key , And read the characters in the buffer directly , Until the characters in the buffer are read , Waiting for the user to press the button .
putchar The function is to output a character to the terminal . The format for int putchar(int c), among c It can be a sheet ( In English ) A leading character , Can be between 0~127 A decimal integer between , It can also be used in advance char A well-defined character variable
边栏推荐
- C language learning log 10.5
- Vercel uses HTTP caching
- QT interface rendering style
- 2022 chlorination process operation certificate examination question bank and simulation examination
- LeetCode第297场周赛(20220612)
- How to understand JS expressions and JS statements
- OJ problem solution summary
- Brick story
- [leetcode]- binary search
- 135. distribute candy
猜你喜欢
Chapter 18 pagination: Introduction
Mind mapping series - Database
PostgreSQL Guide: inside exploration (Chapter 10 basic backup and point in time recovery) - Notes
QT interface rendering style
Chapter 15 mechanism: Address Translation
[leetcode]- binary search
Cesium:cesiumlab makes image slices and loads slices
【JS解决】leedcode 117. 填充每个节点的下一个右侧节点指针 II
Normal distribution (Gaussian distribution)
What is the saturate operation in opencv
随机推荐
C language exercise 1
2022 oxidation process operation certificate examination question bank and simulation examination
Analysis on the similarities and differences of MVC, MVP and mvvc
Draw a hammer
[leetcode]- sliding window
String()和toString()方法得区别
QT realizes message sending and file transmission between client and server
QT using layout manager is invalid or abnormal
Robot pose description and coordinate transformation
Force buckle 92 Reverse linked list II
Clause 48: understand template metaprogramming
Common skills in embedded programming
C language learning log 10.5
D 小红的构造题
Shell built-in string substitution
The differences between the four startup modes of activity and the applicable scenarios and the setting methods of the two startup modes
约瑟夫问题
Blockly learning ----2 Code generation, grid, scaling, events, storage
Clause 31: avoid default capture mode
【JS解决】leedcode 117. 填充每个节点的下一个右侧节点指针 II