当前位置:网站首页>[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

边栏推荐
- Knowledge payment applet dream vending machine V2
- The most effective futures trend strategy: futures reverse merchandising
- 2022 - 021arts: début du deuxième semestre
- Zephyr 学习笔记1,threads
- Unity opens the explorer from the inspector interface, selects and records the file path
- A new understanding of how to encrypt industrial computers: host reinforcement application
- 果果带你写链表,小学生看了都说好
- Amd RX 7000 Series graphics card product line exposure: two generations of core and process mix and match
- Centos8 install mysql 7 unable to start up
- [network data transmission] FPGA based development of 100M / Gigabit UDP packet sending and receiving system, PC to FPGA
猜你喜欢
Review of enterprise security incidents: how can enterprises do a good job in preventing source code leakage?
Zephyr 学习笔记2,Scheduling
It's healthy to drink medicinal wine like this. Are you drinking it right
Selenium ide plug-in download, installation and use tutorial
[Flink] temporal semantics and watermark
Zephyr 學習筆記2,Scheduling
Guoguo took you to write a linked list, and the primary school students said it was good after reading it
Implementation of ZABBIX agent active mode
《剑指Offer》第2版——力扣刷题
Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
随机推荐
Vulhub vulnerability recurrence 76_ XXL-JOB
Guoguo took you to write a linked list, and the primary school students said it was good after reading it
Adaptive spatiotemporal fusion of multi-target networks for compressed video perception enhancement
电子协会 C语言 1级 35 、银行利息
Technical experts from large factories: common thinking models in architecture design
When JDBC connects to es query, is there a God who meets the following situation?
Computer connects raspberry pie remotely through putty
在已经知道表格列勾选一个显示一列
Handwritten easy version flexible JS and source code analysis
[Mori city] random talk on GIS data (I)
2022-021rts: from the second half of the year
[GF (q) + LDPC] regular LDPC coding and decoding design and MATLAB simulation based on the GF (q) field of binary graph
How to input single quotation marks and double quotation marks in latex?
uniapp小程序分包
notepad++如何统计单词数量
JS common time processing functions
Finishing (III) - Exercise 2
[real case] how to deal with the failure of message consumption?
Why does the producer / consumer mode wait () use while instead of if (clear and understandable)
Xcode 14之大变化详细介绍