当前位置:网站首页>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
边栏推荐
- [leetcode]- sliding window
- Clause 30: be familiar with the failure of perfect forwarding
- [try to hack] upload labs (temporarily write to 12)
- Little C's Notepad
- C language learning log 10.8
- Configuration used by automatic teaching evaluation script
- Colab tutorial (super detailed version) and colab pro/pro+ evaluation
- Use service worker to preferentially request resources - continuous update
- Clause 31: avoid default capture mode
- Kaggle time series tutorial
猜你喜欢

Several methods of identifying equivalent circuit of circuit drawing

Analysis of scoped attribute principle and depth action selector

Win8.1和Win10各自的优势

PostgreSQL Guide: inside exploration (Chapter 10 basic backup and point in time recovery) - Notes

Section 5 - Operator details

Converting MySQL data to PostgreSQL with Navicat

Advanced C - Section 3 - character functions and string functions

Analysis on the usage, response and global delivery of provide/inject

MySQL8.0.13安装教程(有图)

Infinite cycle scrolling code Alibaba international station store decoration code base map scrolling black translucent display effect custom content decoration code full screen display
随机推荐
Section 2 - branch and loop statements
Regular expressions in QT
CMB written test graphical reasoning
E - Lucky Numbers
Chinese trumpet creeper
Several methods of identifying equivalent circuit of circuit drawing
OpenCV中的saturate操作(饱和操作)究竟是怎么回事
Shell variable learning notes
How to lay copper in AD (aluminum designer)
[leetcode]- binary search
PowerShell: because running scripts is prohibited on this system, the solution
Article 49: understanding the behavior of new handler
QT realizes message sending and file transmission between client and server
PostgreSQL Guide: inside exploration (Chapter 10 basic backup and point in time recovery) - Notes
PowerDesigner easy to use
Promise processing JS multithreads get the same processing result after all the results are obtained
[try to hack] upload labs (temporarily write to 12)
Sub paragraph of Chapter 16
Cesium:cesiumlab makes image slices and loads slices
Nodejs parsing get request URL string