当前位置:网站首页>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
边栏推荐
- [Yugong series] go teaching course 002 go language environment installation in July 2022
- 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
- MySQL——JDBC
- Study diary: February 14th, 2022
- "Designer universe" APEC safety and health +: environmental protection Panda "xiaobaobao" Happy Valentine's Day 2022 | ChinaBrand | Asia Pacific Economic media
- (5) Web security | penetration testing | network security operating system database third-party security, with basic use of nmap and masscan
- Advanced technology management - how to examine candidates in the interview and increase the entry probability
- Reinforcement learning - learning notes 1 | basic concepts
- MySQL -- standardize database design
- Day 9 HomeWrok-ClassHierarchyAnalysis
猜你喜欢

Memory analyzer (MAT)

Getting started with postman -- environment variables and global variables

Apprentissage intensif - notes d'apprentissage 1 | concepts de base

《ActBERT》百度&悉尼科技大学提出ActBERT,学习全局局部视频文本表示,在五个视频-文本任务中有效!...

MySQL——索引

Notes on MySQL related knowledge points (startup, index)

19、 MySQL -- SQL statements and queries

技术管理进阶——如何在面试中考察候选人并增大入职概率
![Capture de paquets et tri du contenu externe - - autoresponder, composer, statistiques [3]](/img/bf/ac3ba04c48e80b2d4f9c13894a4984.png)
Capture de paquets et tri du contenu externe - - autoresponder, composer, statistiques [3]

Xai+ network security? Brandon University and others' latest "interpretable artificial intelligence in network security applications" overview, 33 page PDF describes its current situation, challenges,
随机推荐
How to modify the network IP addresses of mobile phones and computers?
Study diary: February 14th, 2022
University of Electronic Science and technology | playback of clustering experience effectively used in reinforcement learning
浅议.NET遗留应用改造
[Tang Laoshi] C -- encapsulation: member variables and access modifiers
[gd32l233c-start] 5. FLASH read / write - use internal flash to store data
MySQL -- standardize database design
一台服务器最大并发 tcp 连接数多少?65535?
Basic preprocessing and data enhancement of image data
Sort out several network request methods of JS -- get rid of callback hell
技术管理进阶——如何在面试中考察候选人并增大入职概率
The global industrial design revenue in 2021 was about $44360 million, and it is expected to reach $62720 million in 2028. From 2022 to 2028, the CAGR was 5.5%
[vulnhub shooting range] impulse: lupinone
No more! Technical team members resign collectively
Qt6 QML Book/Qt Quick 3D/基础知识
Single page application architecture
JVM JNI and PVM pybind11 mass data transmission and optimization
阻塞非阻塞和同步异步的区分 参考一些书籍
Cannot load driver class: com. mysql. cj. jdbc. Driver
Leetcode daily question 540 A single element in an ordered array Valentine's Day special article looking for a single dog in a pile of lovers ~ the clown is myself