当前位置:网站首页>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
functionform ,functionIt's the composition C programmaticBasic unit,sentenceIt's the composition C The smallest unit of a program . - One C The program always consists of
The main functionStart 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 、 Underlineform - It can only start with
Letters or underscores
- Identifier is created by
Classification of identifiers :
Be careful :
1、Keywords cannotUsed as user identifier
2、 keywordAll in lowercaseLetter
3、 identifierCase sensitive
4、Predefined identifiers canUsed 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%xCase 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 pointform- 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
IndexpartIt 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 position8、 ... and Decimal integer1 individualcharacter - ‘\xhh’:
1 to 2 positionsixteen Decimal integer1 individualcharacter
- 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 nAs the value of the entire comma expression
边栏推荐
- 如临现场的视觉感染力,NBA决赛直播还能这样看?
- 浅议.NET遗留应用改造
- "Designer universe" argument: Data Optimization in the design field ultimately falls on cost, safety and health | chinabrand.com org
- Rhcsa third day notes
- Kubernetes 通信异常网络故障 解决思路
- Transformer structure analysis and the principle of blocks in it
- What should the future of the Internet be like when Silicon Valley employees flee the big factory and rush to Web3| Footprint Analytics
- 内存分析器 (MAT)
- UI automation test: selenium+po mode +pytest+allure integration
- How to modify the network IP addresses of mobile phones and computers?
猜你喜欢

Scientific research document management Zotero

2022 low voltage electrician examination and low voltage electrician simulation examination question bank

Rhcsa third day operation

Is it OK for fresh students to change careers to do software testing? The senior answered with his own experience

Go learning notes (4) basic types and statements (3)
![[gd32l233c-start] 5. FLASH read / write - use internal flash to store data](/img/4f/ed8ca2f43ba5a8e5da63eb419aae82.jpg)
[gd32l233c-start] 5. FLASH read / write - use internal flash to store data

Haven't expressed the artifact yet? Valentine's Day is coming. Please send her a special gift~

Basic preprocessing and data enhancement of image data

(5) Web security | penetration testing | network security operating system database third-party security, with basic use of nmap and masscan

Hcie security Day12: supplement the concept of packet filtering and security policy
随机推荐
@Transactional注解失效的场景
Etcd 基于Raft的一致性保证
Visiontransformer (I) -- embedded patched and word embedded
抓包整理外篇——————autoResponder、composer 、statistics [ 三]
MySQL 8.0 data backup and recovery
Kubernetes 通信异常网络故障 解决思路
Getting started with postman -- built-in dynamic parameters, custom parameters and assertions
Kernel symbol table
TLS environment construction and plaintext analysis
2022-2-14 acwing1027 grid access
Hcie security Day12: supplement the concept of packet filtering and security policy
How to handle wechat circle of friends marketing activities and share production and release skills
Summary of common operation and maintenance commands
Hcie security Day11: preliminarily learn the concepts of firewall dual machine hot standby and vgmp
Mysql - - Index
不同业务场景该如何选择缓存的读写策略?
Advanced collaboration: coroutinecontext
"Actbert" Baidu & Sydney University of technology proposed actbert to learn the global and local video text representation, which is effective in five video text tasks
"Designer universe" APEC safety and health +: environmental protection Panda "xiaobaobao" Happy Valentine's Day 2022 | ChinaBrand | Asia Pacific Economic media
Capture de paquets et tri du contenu externe - - autoresponder, composer, statistiques [3]