当前位置:网站首页>Preliminary understanding of C program design
Preliminary understanding of C program design
2022-07-03 21:13:00 【Can't learn java】
C Preliminary understanding of program design
1、 ordinary C Program
1.1、C Program Introduction
#include <stdio.h> // Compile preprocessing commands
int main(){
// The main function
printf("HelloWorld");
return 0;
}
- One C Procedure by
function
form ,function
It's the composition C programmaticBasic unit
,sentence
It's the composition C The smallest unit of a program . - One C The program always consists of
The main function
Start execution . - One line can write one or more statements , A statement can also be written on one or more lines .
- It is better to add
;
end .
2、C Language indicator , Constants and variables
The composition of the identifier :
- Identifier is created by
Numbers 、 Letter 、 Underline
form - It can only start with
Letters or underscores
- Identifier is created by
Classification of identifiers :
Be careful :
1、Keywords cannot
Used as user identifier
2、 keywordAll in lowercase
Letter
3、 identifierCase sensitive
4、Predefined identifiers can
Used as user identifier- User identifier
- Predefined identifiers :
scanf( Input function )、pringf( Output function )
include( File contains )、define( Macro definition ) - keyword :32 individual
2.1、 Constant
- Common basic data types include
integer 、 Real type 、 Character
. - Constant : Its value during program operation It can't be changed The amount of .
2.2、 Variable
- Variable : While the program is running , Its value You can change The amount of .
- Variable name : from identifier form .
- Unassigned variables default to random values .
3、 Integer data
Integer data is stored in the form of complement
%d --> Decimal format output
%o --> Output in octal format ( Without the lead )
%x --> Hex format output ( Without the lead , The output format depends on the case%x
Case write )
3.1、 integer constants
- Decimal system
- octal : Leading 0(0123)
- Hexadecimal : Leading 0x or 0X(0X10)
- C There is no binary data in the language
3.2、 Integer variables
int | Basic type | TC2 Bytes /VC4 Bytes |
---|---|---|
short | Short | 2 Bytes |
long | Long integer | 4 Bytes |
unigned | No sign | — |
4、 Real data
%f Output format : Default hold 6 Decimal place , Insufficient 6 Place zero , More than rounding
4.1、 Real constant
- Decimal form : from
Numbers 、 The sign 、 decimal point
form- The rules of composition :
- There has to be
decimal point
- decimal point
At least there are numbers on one side
- There has to be
- The rules of composition :
- Exponential form : from E or e form
- The rules of composition :
- Numbers on both sides
Index
partIt has to be an integer (E/e The right is an integer )
- The rules of composition :
4.2、 Real variable
Single precision | float | 4 Bytes |
---|---|---|
Double precision | double | 8 Bytes |
5、 Character data
5.1、 character constants
Legal character constants :
Enclose one character in single quotation marks
- Regular character constants : A character wrapped in single quotation marks ‘a’ ‘W’ ‘c’ ‘F’
- Escape character constants (6+2 Six basic + Two extensions )
- ‘\n’ —— Carriage returns (Enter)
- ‘\t’ —— Skip horizontally (Tab)
- ‘\b’ —— Backspace (BackSpace)
- ‘\\’ —— The backslash
- ‘\’’ —— Single quotation marks
- ‘\"’ —— Double quotes
- ‘\ddd’:
1 to 3 position
8、 ... and Decimal integer1 individual
character - ‘\xhh’:
1 to 2 position
sixteen Decimal integer1 individual
character
- String constant : Characters wrapped in double quotation marks , End mark ’\0’
5.2、 Character variables
- char: Occupy 1 Bytes
6、 Arithmetic expressions
6.1、 Basic operators
- +、-、*、/、%
a/b
- if a And b They are all integers , The result is an integer
- if a And b Any one of them is real , The result is real
- %( Seeking remainder ): Can only be used for integer
- Remainder Plus or minus Depending on
Divisor
(% On the left )
- Remainder Plus or minus Depending on
6.2、 Precedence and associativity of operators
- priority :
order
() > +( Correct )、-( Take the negative ) > *、/、% > +( Add )、-( reduce ) - associativity : Direction
6.3、 Cast cast character
- form :
( Type name )
expression - evaluation :
- (int)2.2 == 2
- (int)5.5/(int)2.5 == 2
- (int)5.5+2.5 == 7.5
7、 Assignment expression
7.1、 Assignment operator
- form : Variable name
=
expression - priority : Only higher than the comma operator
- associativity : From right to left
7.2、 Compound assignment operator
- +=、-=、*=、/=、%=
- priority : Only higher than the comma operator
- associativity : From right to left
8、 Self addition and self subtraction and comma operators
8.1、 Self addition and self subtraction operators
- form : ++ Variable 、- - Variable 、 Variable ++、 Variable - -
- Be careful : The operation object of self addition and self subtraction must be
Variable
- Pre value usage :++i or - -i
- First, change the variable i The value of the add 1 Or minus 1, And then use i Value .( Change immediately , Use new value )
- Post value usage :i++ or i- -
- Use variables first i Value , And then you put the variables i The value of the add 1 Or minus 1.( Use the old value first , Change again )
- summary :
Variable expression Variable i=2 ++i==3 i==3 i=2 - -i==1 i==1 i=2 i++==2 i==3 i=2 i- -==2 i==1
8.2、 The comma operator
- form : expression 1, expression 2,···, expression n
- priority : The minimum
- associativity : From left to right
Evaluate from left to right , take
expression n
As the value of the entire comma expression
边栏推荐
- Baohong industry | good habits that Internet finance needs to develop
- Yiwen teaches you how to choose your own NFT trading market
- Transformer structure analysis and the principle of blocks in it
- QT6 QML book/qt quick 3d/ Basics
- 如临现场的视觉感染力,NBA决赛直播还能这样看?
- 《ActBERT》百度&悉尼科技大学提出ActBERT,学习全局局部视频文本表示,在五个视频-文本任务中有效!...
- Experience summary of database storage selection
- Ask and answer: dispel your doubts about the virtual function mechanism
- TLS environment construction and plaintext analysis
- Talk about daily newspaper design - how to write a daily newspaper and what is the use of a daily newspaper?
猜你喜欢
Talk about daily newspaper design - how to write a daily newspaper and what is the use of a daily newspaper?
SQL injection - Fundamentals of SQL database operation
JS three families
QT6 QML book/qt quick 3d/ Basics
What is the maximum number of concurrent TCP connections for a server? 65535?
No matter how hot the metauniverse is, it cannot be separated from data
Link aggregation based on team mechanism
技术管理进阶——如何在面试中考察候选人并增大入职概率
XAI+网络安全?布兰登大学等最新《可解释人工智能在网络安全应用》综述,33页pdf阐述其现状、挑战、开放问题和未来方向
MySQL master-slave synchronization principle
随机推荐
Ask and answer: dispel your doubts about the virtual function mechanism
TiDB 之 TiCDC6.0 初体验
SQL injection - Fundamentals of SQL database operation
Service discovery and load balancing mechanism -service
设计电商秒杀系统
@Transactional注解失效的场景
Transformer structure analysis and the principle of blocks in it
TLS environment construction and plaintext analysis
Install and use Chrony, and then build your own time server
Qualcomm platform WiFi update disconnect end open event
Kernel symbol table
APEC industry +: father of the king of the ox mill, industrial Internet "king of the ox mill anti-wear faction" Valentine's Day greetings | Asia Pacific Economic media | ChinaBrand
Wireless network (preprocessing + concurrent search)
Use nodejs+express+mongodb to complete the data persistence project (with modified source code)
Measurement fitting based on Halcon learning -- Practice [1]
@Scenario of transactional annotation invalidation
Etcd 基于Raft的一致性保证
No more! Technical team members resign collectively
"Designer universe" argument: Data Optimization in the design field ultimately falls on cost, safety and health | chinabrand.com org
Apprentissage intensif - notes d'apprentissage 1 | concepts de base