当前位置:网站首页>[C language] open the door of C
[C language] open the door of C
2022-07-04 07:24:00 【InfoQ】
C What is language
C What are the advantages of language over other languages
- Less resources
- Fast running speed
- It is convenient to operate the hardware
- If you want to learn Embedded Development , And communications , The first choice is C Language .
- C Language is a senior big brother (ง •_•)ง
C Characteristics of language
- Efficiency : Did it " And have both ", From here C The history of language can be known .
- flexibility : C Language syntax can be created from the original code syntax , So as to give programmers more room to play .
- Rich in functions : You can use a lot of rich operators ( Arithmetic operator 、 concatenation operator 、 Relational operator 、 Assignment operator and Logical operators ) And custom structure types , Express any complex data type
- Expressive power : linguistic form , Freedom of writing , Structural specifications are complete , After light control .
- Good portability : C Under different operating systems , Simply modify or not modify , Cross platform program development .
Print hello word
#include<stdio.h>
int main(void)
{
printf("hello word\n");
return 0;
}- The first 3 That's ok , This int With a watch means shaping , So thismainIs the name of the main function , It means that this is a main function , Bear in mind :every last C Procedures must have main function , And there is and only one in the whole C In the process ,Any program is from main Function executed .
- The first 4 Xing He 6 That's ok ,{ }( The use of scope improves the locality of program logic , Enhance program reliability , Reduce code to code conflicts ).
- The first 5 That's ok , Function call statements ,printf The functionality :Send the content to be output to the display screen to display ( Print ), Is a standard library function , Can be called between programs .Be careful :'\n' It stands for < Line break > It means .
- The first 7 That's ok ,return return ,0 plastic , Back to main Among functions , There's nothing to say .
- Be careful : When writing code, typeCharacters must be in English , Characters must be in English , Characters must be in English Say important things three times \(@^0^@)/
complete C Program
#include<stdio.h>
// arr It's essentially a pointer
int binary_search(int arr[],int k,int sz)
{ // Implementation of algorithm
int left = 0;// The first subscript of the left array
// The first subscript of the right array
int right = sz - 1; /* 1 2 3 4 5 6 7 8 9 10
// Find the middle element subscript according to the left and right subscripts 0 1 2 3 4 5 6 7 8 9 */
while (left<=right)// When left be equal to right It means you've found k The subscript
{
int mid = (left+right)/2;
if (arr[mid] < k) // If mid Elements (4) Than the elements I'm looking for (6) want < Words
{
left = mid + 1; //4+1=5 This refers to the element
}
else if (arr[mid] > k)// If mid Elements (4) Than the elements I'm looking for (6) want > Words
{
right = mid - 1; //4-1=3
}
else
{
return mid; // return mid Go to the function
}
}
return 1;// Not found. Return to 1
}
int main(void)
{
// Two points search
// Find a specific number in an ordered array
// If found, return the index of this array , No return found -1.
int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int k = 7;
int sz = sizeof(arr) / sizeof(arr[0]);//sz Number of elements
//ret Receive return value here arr Only the address of the first element of the array is passed
int ret = binary_search(arr,k,sz);// call ( Two points search ) function
if (ret == 1)
{
printf(" Array subscript not found ");
}
else
{
printf(" Find array subscript :%d\n", ret);
}
return 0;
}notes
Print function and input function ( Focus on understanding )
- Blank character : This function will read and ignore any white space characters encountered before the next non white space character ( White space characters include space 、 New lines and tab characters - see isspace --isspace, Computer functions , Mainly used to check parameters c Whether it is a blank character .) A single white space in the format string validates any number of white space characters extracted from the stream ( Does not include any white space characters ).
- Nonwhite space character : Format specifier (%) With the exception of : Any character that is not white space ( blank 、 New lines or labels ) Or format specifier ( With % The beginning of a character ) A part of the character will cause the function to read the next character from the stream , Compare it with this non white space character , If the match , Throw it away , And this function continues to use the next character of the format . If the characters don't match , The function will fail , The subsequent characters that return and leave the stream are unread .
- Format specification : By the initial percentage symbol (%) The resulting sequence represents the format specifier , Used to specify the type and format of data to be retrieved from the stream and stored in the location indicated by other parameters .
- Last , I'm talking about , I / O function (scanf and printf) Is the most frequently used function , You must focus on , Especially format input and output ,C The key and difficult points of language , In fact, this kind of play and learn more in the back , Of course . So stick to it .
C Structural features of language programs
Programming specification
C Language character set
- First , Let's talk about : Characters are the most basic elements of a language .C Language characters consist of :
- Letter : Lowercase letters a~z, Capital A~Z, , respectively, 26 individual .
- Numbers : Arabic numerals 0~9 common 10 individual .
- Space : Let's talk about its types and forms here :
- A key on a computer keyboard , Usually in the bottom line of the keyboard , It is the longest key on the computer keyboard . Represents an empty space , It's in GBA The simulator plays a role of acceleration in the default controller .
- Computer knowledge , Spaces are counted as one character , So when you fill out a form on the website , You can write nothing , But don't press the spacebar in blank items , When you search in search engines , If you forget a word , Space can be used to temporarily replace . Spaces can also be used as small lattices, hollow lattices .
- GBA expand : A simulation GBA Game software , It can be in Africa GBA Run through simulation in the platform GBA( Nintendo's second-generation portable game console ) game , When running the game, you also need to have the corresponding game ROM( read-only memory ).
- Punctuation and identifiers : Punctuation has nothing to say , Let's focus on the next identifier
- finger : A symbol used to identify an entity , It has different meanings in different application environments .

identifier
Last

边栏推荐
- Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
- A new understanding of how to encrypt industrial computers: host reinforcement application
- Su Weijie, a member of Qingyuan Association and an assistant professor at the University of Pennsylvania, won the first Siam Youth Award for data science, focusing on privacy data protection, etc
- Cell reports: Wei Fuwen group of the Institute of zoology, Chinese Academy of Sciences analyzes the function of seasonal changes in the intestinal flora of giant pandas
- Campus network problems
- Introduction to sap commerce cloud B2B organization function
- Bottom problem of figure
- Transition technology from IPv4 to IPv6
- Responsive mobile web test questions
- Label management of kubernetes cluster
猜你喜欢

A new understanding of how to encrypt industrial computers: host reinforcement application

响应式——媒体查询

Responsive mobile web test questions

Responsive - media query

Transition technology from IPv4 to IPv6

大学阶段总结

Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg

Master-slave replication principle of MySQL database

Node foundation ~ node operation

Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
随机推荐
Finishing (III) - Exercise 2
JS common time processing functions
The IP bound to the socket is inaddr_ The meaning of any htonl (inaddr_any) (0.0.0.0 all addresses, uncertain addresses, arbitrary addresses)
Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
[Flink] temporal semantics and watermark
Detailed introduction to the big changes of Xcode 14
Summary of June 2022
Adaptive spatiotemporal fusion of multi-target networks for compressed video perception enhancement
Literature collation and thesis reading methods
Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
CMS source code of multi wechat management system developed based on thinkphp6, with one click curd and other functions
The most effective futures trend strategy: futures reverse merchandising
Unity 从Inspector界面打开资源管理器选择并记录文件路径
Chain ide -- the infrastructure of the metauniverse
BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
[GF (q) + LDPC] regular LDPC coding and decoding design and MATLAB simulation based on the GF (q) field of binary graph
Introduction to rce in attack and defense world
《剑指Offer》第2版——力扣刷题
Crawler (III) crawling house prices in Tianjin
Vulhub vulnerability recurrence 77_ zabbix