当前位置:网站首页>Fundamentals of C language
Fundamentals of C language
2022-07-25 08:36:00 【Programmer Ziling】
C As soon as language comes out, it is concise and compact 、 Flexible and convenient . Easy to calculate 、 Rich data structure 、 Wide range of application 、 The characteristics of high execution efficiency have been rapidly promoted all over the world .c Language is also the ancestor of many other high-level languages , So study c Language is a required course to enter the programming world .
One C The writing rules of language
(1) A description or statement takes up a line .
(2) Use curly braces {} The enclosed part , It usually represents a layer structure of a program .{} It is usually aligned with the first letter of the structure statement , And take a single line .
(3) A lower level statement or description can be written after indenting several characters than a higher level statement or description ( General indent 2 English characters ), To make it look clearer , Increase the sustainability of the program .
(4) When an executable statement ends, it needs a semicolon at the end .
Two 、C Concrete structure of language
Simply speaking , One C The program is composed of several header files and functions . example :
#include"stdio.h" \* Will library file stdio.h Included in this file *\
int main() \* Main function name *\
{ \*main Function body start *\
printf("Hello World\n"); \* Output a string on the screen ,\n Is a newline *\
} \*main End of function body *\
(1)‘‘#include"stdio.h"” It's a preprocessing command , use ‘‘#’’ start , among stdio.h yes C Header file of language program . The file contains input / Output function information .
(2) One C The program has multiple functions , But there is only one main function ; It's a function main And execute from the main function .
(3) The main function main Ahead int Is the type of main function .
Program notes
Comments are written for programmers , It's not written for computers .
There are two types of comments :
Multiline comment :/* The comment */
Single-line comments : // Comment line
3、 ... and 、 Basic data types in programs

The most commonly used integer , Real and character
(char,int,float,double):
data type explain byte application List
char Character 1 Used to store a single character char sex=‘M’
int integer 2 Used to store integers int height=18;
float Single precision floating point 4 Used to store decimals float price=13.1
double Double precision floating point 8 Used to store decimals with more digits double pi=3.1415926
(1) Identifiers can only be made of letters 、 Numbers and underscores , The first character must be a letter or an underline .C Identifier in language :
The rules explain
Can only be underlined 、 Numbers and letters form , The first character must be a letter or an underline , It cannot be numbers or other symbols Such as sum,score,Area _abc Are correct identifiers Be careful C Distinguish between upper and lower case letters in language
You can't use system keywords If you can't use int、float、char、main Other system keywords
You cannot use the system predefined notation Such as compiling preprocessing commands (define、include) And system function name (scanf、printf、getchar) And other system predefined identifiers cannot be used
Try to use easy to understand names , Achieve “ Know what you know ” If available max、name、 etc. , Out of commission x1,x2 Etc. as identifiers
Avoid using confusing characters Avoid using I( english )、1( Numbers ),0,o etc.
(2) keyword
Keywords representing data types (14 individual ) int,long,short,char,float,double,signed,unsigned,struct,union,enum,void,volatile,const
Keywords that identify the storage type (5 individual ) auto,static,register,extern,typedef
Identify keywords for process control (12) goto,return,break,continue,if,else,while,do,for,switch,case,default
Keywords that identify operators (1) sizeof
Four 、 Variables and assignments
(1) Variable Overview
Variable refers to the amount that the stored value can be changed during the operation of the program , Define variables before using them ; To distinguish between variable name and variable value is two different concepts .
Columns such as :
(2) Variable description
The variable definition form is generally : Variable name data type

All variables must be explained before use , A variable description statement consists of a data type and one or more subsequent variables .
Columns such as :
int zpc; // An integer variable is defined , The variable name is num
zpc=100; // to num The variable is assigned to 100
int a,b,c; // Declare multiple variables at the same time , Then assign values respectively
a=1;
b=2;
c=3;
printf("%d\n",zpc); // Print integer variables zpc
Be careful : Continuous assignment is not allowed in the definition , Such as int a=b=c=6; Is the wrong operation .
5、 ... and 、 Constant
During program execution , A quantity whose value does not change becomes a constant .
Constants fall into the following categories :
(1) integer constants :14、0、-14;
(2) Real constants are also called floating point numbers :15.3、13.1;
(3) character constants :‘z’、‘p’
() String constant :"I LOVE ZSS!"
printf("%d\n",100); // integer constants
printf("%f\n",3.14); // Real constant
printf("%c\n",'Z'); // character constants
printf("I LOVE ZSS!"); // character constants
6、 ... and 、 Operation symbol
C Types of language operators
priority Operator name Operator type Combining with the way
1
() Brackets ( Functions, etc )
From left to right
【】 The array subscript From left to right
.、->
!
Structural members
Logic is not
From left to right
~ According to the not
++、-- Self increasing 、 Self reduction
2 +、- just 、 negative Monocular operator From right to left
( type ) Cast
* The pointer
& Address fetch
sizeof Calculate the data type length
(2) Self increasing and self decreasing operators
1、
Operation expression explain Operational rules
++a a Self increasing 1 after , Then take . Calculate first , Then take
--a a Self reduction 1 after , Then take . Calculate first , Then take
a++ a After taking the value ,a And then the value of 1 Take value first , Re operation
a-- a After taking the value ,a The value of is reduced by itself 1 Take value first , Re operation
#include "stdio.h"
void main()
{
int i=3,j;
j=++i+i++; /* Put the previous one i increase 1 Then carry out two i Add up , namely 4+48/
printf("i=%d,j=%d\n",i,j);
i=3;
j=(++i)+(++i)+(++i); /* First the i Self adding 3 Time , then 3 individual i Self adding */
printf("i=3,j=(++i)+(++i)+(++i),");
printf("i=%d,j=%d\n",i,j);
i=3;
j=(i++)+(i++)+(i++); /* First the 3 individual i Add up , then i Self adding 3 Time */
printf("i=3,j=(i++)+(i++)+(i++),");
printf("i=%d,j=%d\n",i,j);
i=3;
printf("%d,%d,%d\n",++i,++i,++i); /* First move from right to left i Output items after self addition */
i=3;
printf("%d,%d,%d\n",i++,i++,i++); /* Output items from right to left i Self adding */
}
边栏推荐
- RTOS系列(13):汇编LDR指令、LDR伪指令、[Rn]寄存器间接引用 详细解析
- Dirty data and memory leakage of ThreadLocal
- Graduation design of wechat small program ordering system of small program completion works (3) background function
- @Autowired注解的原理
- [dark horse programmer] redis learning notes 001: introduction to redis + five basic data types
- JS cool rolling picture deformation animation JS special effects
- Network solutions for Alibaba cloud services
- 提高代码可续性的小技巧,以connectTo方法为例。
- [5g NR] 3GPP common protocol sorting
- @Principle of Autowired annotation
猜你喜欢
随机推荐
Raspberry pie creation self start service
一款强大的端口扫描工具(nmap)
Blue and white porcelain used by Charles
[dark horse programmer] redis learning notes 003: redis transactions
@Implementation principle of Autowired annotation
Online bookstore system based on jsp+servlet+mysql
[5g NR] 3GPP common protocol sorting
Force buckle - 1046. Weight of the last stone
@Feignclient annotated interface. You may not get instances with @autowired
This week's big news | FCC exposed Pico 4 VR all-in-one machine, and leipeng's parent company established a smart glasses laboratory
Mogdb 3.0 how to add a standby database in the environment of one active and one standby
Huawei device remote login (Telnet, SSH) configuration
Svg creative underline style JS special effect
Literature learning (part101) -- converge clustering
JVM specification Oracle official website
@The difference and use of value and configurationproperties
Idea2021 failed to start. Could not find main class com/intellij/idea/main
Use of lambdaquerywrapper, lambdaupdatewrapper, lambdaquerychainwrapper
第3章业务功能开发(实现全选按钮实时的响应)
Rstudio shows that it can't connect to the web page, or it has a new website.








