当前位置:网站首页>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
边栏推荐
- 同花顺开户注册安全靠谱吗?有没有风险的?
- Kubernetes abnormal communication network fault solution ideas
- 2022 low voltage electrician examination and low voltage electrician simulation examination question bank
- Line segment tree blue book explanation + classic example acwing 1275 Maximum number
- Hcie security Day12: supplement the concept of packet filtering and security policy
- 鹏城杯 WEB_WP
- 电子科技大学|强化学习中有效利用的聚类经验回放
- Reinforcement learning - learning notes 1 | basic concepts
- JS three families
- Analyse de REF nerf
猜你喜欢
![[vulnhub shooting range] impulse: lupinone](/img/27/b92eeceefd1c71f19d926bdd1eee8b.jpg)
[vulnhub shooting range] impulse: lupinone

Install and use Chrony, and then build your own time server

Interval product of zhinai sauce (prefix product + inverse element)

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

Talk about daily newspaper design - how to write a daily newspaper and what is the use of a daily newspaper?

No more! Technical team members resign collectively

Discussion Net legacy application transformation

Basic preprocessing and data enhancement of image data

Experience summary of database storage selection

UI automation test: selenium+po mode +pytest+allure integration
随机推荐
[Yugong series] go teaching course 002 go language environment installation in July 2022
leetcode-540. A single element in an ordered array
淺析 Ref-NeRF
Design e-commerce seckill system
一台服务器最大并发 tcp 连接数多少?65535?
【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
Set, weakset, map, weakmap in ES6
Gauss elimination solves linear equations (floating-point Gauss elimination template)
Capturing and sorting out external articles -- autoresponder, composer, statistics [III]
"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
MySQL——规范数据库设计
电子科技大学|强化学习中有效利用的聚类经验回放
Install and use Chrony, and then build your own time server
Operate BOM objects (key)
The "boss management manual" that is wildly spread all over the network (turn)
Is it OK for fresh students to change careers to do software testing? The senior answered with his own experience
Brief analysis of ref nerf
Interval product of zhinai sauce (prefix product + inverse element)
鹏城杯 WEB_WP
Single page application architecture