当前位置:网站首页>C language learning summary (I) (under update)
C language learning summary (I) (under update)
2022-07-06 14:35:00 【|Light|】
c Language summary
Software used
This is a 2022 Articles written in , So I suggest you use vs2022 , The software is free
At the same time, it supports and is compatible win11 System , Is compiled c The most professional language , The most perfect software , Personally think that
Not one of them. , The only downside , The software itself is a little big , Need some storage space
Prepare to start writing programs
We click create new project , Click the empty item and select the path of the file you want to store ,
And its name , The next step is to create a project , Then right-click the source file on the right , Select add new item , choice c++ File items
Quickly add templates
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns=" http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet ">
<CodeSnippet Format="1.0.0">
<Header>
<Title>mainc</Title>
<Shortcut>mainc</Shortcut>
<Description>mainc Function automatically generates </Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Code Language="cpp"><![CDATA[
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main()
{
system("pause");
return 0;
}
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Copy the above code
Create a new... On the desktop .txt File put the code in , Then change the file extension to .snippet Format . No, you can confide in me , Because it's so simple .
And then click vs The tools on the inside , Select Code Snippet Manager , Click Add , Just put the file in and click next
such , We input in the source file just now mainc, Press enter Key will automatically output the template
Text
Basic data type
In computer advanced languages , There are two types of data representation : Constants and variables .
Constant
Constant means 1 2 3,a,b etc. , there a,b Will be changed into its corresponding number by the computer ,
Specific reference ascll clock
Specific constants refer to the following
One integer constants : Such as 1,2,3, And the letters ;
Decimal number : Such as 123.456 , 0.0 , 10.0 etc. ;
Two Exponential form : Such as 12.34e3( The computer cannot use superscript , So use e or E To represent the bottom ten index ,e There have to be numbers in front of you ,e It must be followed by an integer .);
3、 ... and character constants
Divided into two
- Ordinary character constants
Such as ’a’ ,'b’ etc. , For the character a , b; - Escape character
|‘\n’| Line break |
|‘\t’| It's equivalent to clicking Tab|
|‘\a’| Warning sound prompt |
|‘\r’| enter |
|‘\f’| Change the page |
|‘\o’| octal |
|‘\x’| Hexadecimal |
|‘\0’| Null character |
wait
Four String constant
Such as “123” “ABC”
5、 ... and Symbolic constant
use #define A constant is represented by a symbol after the specified by the instruction, such as :
#define cd 584846
Is to make cd Instead of 584846.
6、 ... and address constant
The address of data stored in memory cannot be changed when the program is running , It is called address constant .
Variable
A variable is the amount by which its value can be changed while the program is running
Variables must first be defined in use
The naming rules should conform to the identifier naming rules
Identifier naming rules :
Only letters , Numbers , Underline composition , Can only start with letters and underscores
In the same scope , You can't have the same name , Keywords are not allowed , Such as :
Can not write int.
data type
In the computer , Data is treated separately , Mainly related to the accuracy of memory and so on , Accuracy is limited , If the decimal point after the value is too large , Future numbers may be recorded incorrectly
Basic types
plastic int , It can only be integers Range -32768 To 32767 Occupy 4 byte
Character char Defining characters , You can also store integers Occupy 1 byte , Chinese accounts for 2 byte , Specific reference ascll surface
Single decimal float Store decimals Occupy 4 byte
Double decimal Store decimals Occupy 8 byteConstruction type
An array type
Structure type struct
Joint type union
Enumeration type enumAn array type
You can add these before the types to control them
The absolute value unsigned
normal signed
More accurate storage long Occupy 8 byte
Storage is more inaccurate short Occupy 2 byte
The more accurate it is, the more memory it takes
Such as
unsigned long long int i;
That is, it defines a double long unsigned integer
Data input and output
- Output printf putchar puts fputs
- Input scabf getchar gets fgets
printf function
printf(" What to output ");
You can also output variables
printf(" Escape character corresponding to variable name ", Defined variable name );
- %d, Corresponding decimal system int;
- %f, Corresponding float;
- %c, Corresponding char;
- %s, Corresponding string type array ;
- %ld, Corresponding long;
- %sd, Corresponding short;
- %o, Corresponding to octal int;
- %x, Hexadecimal int;
- %lf, Corresponding double;
- %e, Scientific enumeration ;
You can also add \n , \t etc.
When outputting, you can control the accuracy of the output value , for example
printf("%.1f",i);
intend i The maximum value of is after the decimal point 1 position , The extra will be 4 House 5 Enter into
scanf
and printf similar
scanf(" Characters that the user must enter + Escape character corresponding to variable ",& Variable ,& Variable );
The above function is used to pay the content entered by the customer to the corresponding variable
getchar and putchar
i = getchar();
putchar(i);
The above is used to get One Character to i, Then the output i The content of ,getchar Only one character can be obtained
gets,puts
The first line of code should add a header file
#include<stdlib.h>
gets and puts Is a function that operates on strings
For example, an array a[10],
gets(a);
puts(a);
Press enter To end typing
But if you enter 99 Characters , Out of range of array ,gets The function does not determine the upper limit , The rest will not be added, so there is fgets.
puts Function will automatically add line breaks , So there is fputs.
fgets And fputs
and gets Contains the same header file
fgets( Array name , Storage size ,stdin);
fputs Line breaks are not automatically added at the end
fputs( Array name ,stdout);
skill
scanf And getchar Function can play the role of pause
Because if the user doesn't input , The program will not execute downward
Operators and expressions
Basic type operators
That is, addition, subtraction, multiplication and division , Computer division is primary school division
a/b=c more than d
That is to say, the result of division is an integer
To get decimals
To do this
a%b
% Represents the remainder except for integers
Self increasing and self reducing operation
Self increase is to add 1, Self reduction is to reduce one , Here is an example of self increment
a++ and ++a Said the increase ,a– and –a Indicates self subtraction
Their priority will be high ,
a++ and ++a After the operation, it means a=a+1
The difference lies in a++ Yes, it will call a The value of is giving a add 1
++a It's for a Add 1, Calling a Value
such as
c = a++;
c = ++a;
The result above is c The value of is a
The following result is c The value of is a+1
Generally, when writing programs, it is not allowed to use when there are differences between the two , Because the program will be difficult to understand if it is written , Sometimes confused , Originally, I didn't talk about this , But now universities love to take exams .
c = i+++a;
Do you know what I mean by this program ?
operation
The mathematical operation of a computer is similar to mathematics. Parentheses and multiplication and division have priority over addition and subtraction , Autoincrement operation is the highest
What I want to say here is int and float or double And so on
Of course , Just as you think ,int And float perhaps double The result of the operation will become double type
char The type operation will be converted to the corresponding ascll Code value
int And unsigned The operation will first put int Turn into unsigned type , recompute
Of course , You can also force their operation results to the data type you want
Just add
( data type )
That's all right. , for example a+b After c yes double type , I am now forced to convert to int type
c = (int)a + b;
It should be noted that , The converted value is a temporary value , The data itself is still the original type , Next time, the original data type will be used
More operators
Except arithmetic operators , also
- Relational operator (<,>,==,>=,<=,!=( It's not equal to )) And really (1), false (0)
- Logical operators ( And (&&) or (||) Not (!))
- An operator ( Move left << , Move right >> , Bitwise AND & , Press bit or | , Bitwise XOR ^)
- Assignment operator (+= ,-=,*=,/=,%=)
- Ternary conditional operator (( Conditions 1)?( Conditions 2):( Conditions 3))
The operation result of relational operator and conditional operator is true or false , That is to say 1 perhaps 0
Bitwise operators are generally not used , It refers to moving the binary code corresponding to the character to the left and right , It can only be used in specific situations , Or in some data structures
Assignment operator
Take up a += Example
a+=b It's equivalent to a = a + b
The key point is the trinocular operator
He means
Once the condition is established ?, Implement the conditions upon establishment 2, No execution conditions 3
There is no need to explain other operators
Here is the priority of operators
Broadly speaking
Monocular is larger than binocular is larger than tricular .
Count > Relationship > Logic > Conditions > assignment > comma
See Baidu for details
https://cn.bing.com/search?q=c%E8%AF%AD%E8%A8%80%E8%BF%90%E7%AE%97%E7%AC%A6%E4%BC%98%E5%85%88%E7%BA%A7%E9%A1%BA%E5%BA%8F%E8%A1%A8
c sentence
Slave language is composed of multiple source program files , A source file consists of multiple functions , It consists of processing files and global variable declarations
c The basic constituent unit of is function , The function is composed of multiple c Sentence composition
Sentence classification
Assignment statement
stay c in , = Indicates assignment , Give the right value to the left , Two = That is to say == Is the equal signExpression statement
Is an expression plus a semicolon , Such as
c = 2;
No dice , Teachers have cerebral palsy , Love these
- Control statement
There are nine , I'll talk about it in detail later
1 .if()…else()…
2 . for( ; ; )…
3 . while()…
4 . do…while…
5 . break;
6 . continue;
7.switch
8 . return
9.goto - Function call statements
It refers to the function in the call header file
Such as
Use what we said before printf
It's called
#include<stdio.h> The function in - Empty statement
Single ; It's an empty statement , Just nothing , It's just that wayward - Compound statement
It refers to the statements with parentheses
边栏推荐
- 指针 --按字符串相反次序输出其中的所有字符
- MySQL interview questions (4)
- Web vulnerability - File Inclusion Vulnerability of file operation
- 数字电路基础(一)数制与码制
- Fundamentals of digital circuit (V) arithmetic operation circuit
- Low income from doing we media? 90% of people make mistakes in these three points
- 《统计学》第八版贾俊平第十三章时间序列分析和预测知识点总结及课后习题答案
- 5分钟掌握机器学习鸢尾花逻辑回归分类
- Build domain environment (win)
- 安全面试之XSS(跨站脚本攻击)
猜你喜欢
Intranet information collection of Intranet penetration (I)
Intranet information collection of Intranet penetration (5)
How does SQLite count the data that meets another condition under the data that has been classified once
《统计学》第八版贾俊平第六章统计量及抽样分布知识点总结及课后习题答案
Ucos-iii learning records (11) - task management
New version of postman flows [introductory teaching chapter 01 send request]
内网渗透之内网信息收集(三)
Proceedingjoinpoint API use
Interview Essentials: what is the mysterious framework asking?
Attack and defense world misc practice area (GIF lift table ext3)
随机推荐
【指针】数组逆序重新存放后并输出
Low income from doing we media? 90% of people make mistakes in these three points
Xray and burp linkage mining
《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案
Network technology related topics
《统计学》第八版贾俊平第八章假设检验知识点总结及课后习题答案
指针:最大值、最小值和平均值
【指针】删除字符串s中的所有空格
How to earn the first pot of gold in CSDN (we are all creators)
《英特尔 oneAPI—打开异构新纪元》
数字电路基础(一)数制与码制
攻防世界MISC练习区(SimpleRAR、base64stego、功夫再高也怕菜刀)
Statistics, 8th Edition, Jia Junping, Chapter 11 summary of knowledge points of univariate linear regression and answers to exercises after class
【指针】求解最后留下的人
5分钟掌握机器学习鸢尾花逻辑回归分类
ES全文索引
Fundamentals of digital circuit (IV) data distributor, data selector and numerical comparator
Build domain environment (win)
四元数---基本概念(转载)
循环队列(C语言)