当前位置:网站首页>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
边栏推荐
- Optocoupler working principle function electric parameter application circuit
- Nodejs parsing get request URL string
- RuoYi-Cloud启动教程(手把手图文)
- C#获取WebService接口的所有可调用方法[WebMethod]
- How to implement a custom jdbc driver in only four steps?
- Analysis on the usage, response and global delivery of provide/inject
- 135. distribute candy
- QT brushes and brushes
- Trust programming - linked lists: use struct to implement linked lists, use heap to merge K ascending linked lists, and customize display
- Must know must know -c language keywords
猜你喜欢
Section 3 - functions
QT direction key to move focus
【JS解决】leedcode 117. 填充每个节点的下一个右侧节点指针 II
Advanced C language - Section 1 - data storage
Internet people a few years ago vs Internet people today
Chapter 15 mechanism: Address Translation
Kaggle 时间序列教程
Analysis on the similarities and differences of MVC, MVP and mvvc
Shell built-in string substitution
C # get all callable methods of WebService interface [webmethod]
随机推荐
Advanced C - Section 2 - pointers
Your one-on-one meetings are inefficient. You can do this!
Win8.1和Win10各自的优势
Ruoyi cloud startup tutorial (hand-held graphics)
约瑟夫问题
Mind mapping series - Database
CMB's written test -- data analysis
C language learning log 10.8
Common skills in embedded programming
无限循环滚动代码阿里巴巴国际站店铺装修代码底图滚动黑色半透明显示效果自定义内容装修代码全屏显示
QT using layout manager is invalid or abnormal
[JS solution] leedcode 200 Number of islands
Sub paragraph of Chapter 16
QT direction key to move focus
2022 chlorination process operation certificate examination question bank and simulation examination
Blockly learning ----2 Code generation, grid, scaling, events, storage
Analysis of the principle of V-model and its application in user defined components
Handwritten promise and its method, with detailed notes
General communication protocol for industrial Internet
Spread your wings and soar