当前位置:网站首页>[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
边栏推荐
- Technical experts from large factories: common thinking models in architecture design
- Centos8 install mysql 7 unable to start up
- Transition technology from IPv4 to IPv6
- [Flink] temporal semantics and watermark
- Node connection MySQL access denied for user 'root' @ 'localhost' (using password: yes
- What is the use of cloud redis? How to use cloud redis?
- jdbc连接es查询的时候,有遇到下面这种情况的大神嘛?
- Set JTAG fuc invalid to normal IO port
- Introduction to sap commerce cloud B2B organization function
- 提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
猜你喜欢
Four sets of APIs for queues
Review of enterprise security incidents: how can enterprises do a good job in preventing source code leakage?
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
Crawler (III) crawling house prices in Tianjin
The number of patent applications in China has again surpassed that of the United States and Japan, ranking first in the world for 11 consecutive years
Zephyr study notes 2, scheduling
Rhcsa the next day
Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
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)
[kubernetes series] kubesphere is installed on kubernetes
随机推荐
What is the use of cloud redis? How to use cloud redis?
The final week, I split
Cochez une colonne d'affichage dans une colonne de tableau connue
Rhcsa day 3
Chapter 1 programming problems
flask-sqlalchemy 循环引用
在已經知道錶格列勾選一個顯示一列
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
节点基础~节点操作
If there are two sources in the same job, it will be reported that one of the databases cannot be found. Is there a boss to answer
[Mori city] random talk on GIS data (I)
Experience installing VMware esxi 6.7 under VMware Workstation 16
The most effective futures trend strategy: futures reverse merchandising
Zephyr Learning note 2, Scheduling
Unity opens the explorer from the inspector interface, selects and records the file path
Transition technology from IPv4 to IPv6
Routing decorator of tornado project
Zephyr 学习笔记1,threads
电子协会 C语言 1级 35 、银行利息
Electronic Association C language level 1 34, piecewise function