当前位置:网站首页>Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence
Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence
2022-07-03 03:14:00 【ihan001】
List of articles
One 、C Sentence structure

1. Control statement :
① if()…else…( Conditional statements )
② for()…( Loop statement )
③ while()…( Loop statement )
④ do…while ()( Loop statement )
⑤ continue( End the loop )
⑥ break( To suspend execution switch Or loop statement )
⑦ switch( Multi branch select statements )
⑧ return( Return statement from function )
⑨ goto( Turn to statement , In structured programs, there is basically no need to goto sentence )
() Indicates that there is a discriminant condition in brackets
… Represents an embedded statement
2. Function call statements
A function call statement consists of a function call plus a semicolon .
printf("I am ihan001. ");
among printf("I am ihan001. "); It's a function call , Add a semicolon to make a statement .
3. Expression statement
An expression statement consists of an expression plus a semicolon , The most typical is that an assignment statement is composed of an assignment expression . for example :
a=3
Is an assignment expression , and
a=3;
It's an assignment statement .
4. Empty statement
;
A statement with only one semicolon is an empty statement .
Can be used as a turning point in the process ( The flow goes from other parts of the program to this sentence );
It can also be used as the loop body in a loop statement ( The loop body is an empty statement , Indicates that the loop does nothing ).
5. Compound statement
It can be used {} Put some sentences and statements together to form a compound sentence ( Also known as statement block ).
{
float pi=3.14159, r=2.5, area; // Defining variables
area=pi*r*r;
printf("area=%f",area);
}
Compound statements are often used in if Statement or loop , At this time, the program needs to execute a set of statements continuously .
The semicolon at the end of the last statement in a compound statement cannot be ignored without writing .
Two 、 Assignment statement
give an example 1: Give the three sides of a triangle , Find triangle area .
Ideas :area=√s(s−a)(s−b)(s−c), among s=(a+b+c)/2.
#include <stdio.h>
#include <math.h>
int main ()
{
double a,b,c,s,area; // Define variables , Are all double type
a=3.00; // To the side chief a assignment
b=5.00; // To the side chief b assignment
c=4.00; // To the side chief c assignment
s=(a+b+c)/2; // Calculation s
area=sqrt(s*(s-a)*(s-b)*(s-c)); // Calculation area
printf("a=%f\tb=%f\t%f\n",a,b,c); // Output trilateral a,b,c Value
printf("area=%f\n",area); // Output area area Value
return 0;
}

3、 ... and 、 Assignment operator
“=” The function of is to assign a data to a variable .
for example :a=3 The function of is to perform an assignment operation ( Or assignment operation ). Put constant 3 Assigned to a variable a.
You can also assign the value of an expression to a variable .
Four 、 Composite operators
In the assignment = Add the other operators before , Operators that can form compounds .
a+=3 Equivalent to a=a+3
x*=y+8 Equivalent to x=x*(y+8)
x%=3 Equivalent to x=x%3
Usually binary ( Two eyes ) Operator , Can be combined with the assignment character to form a composite assignment character .
The compound assignment operators related to arithmetic operations are +=,-=,=,/=,%=.
Be careful :
If the right side of the assignment character is an expression containing several items , It has parentheses . for example ,
x%=y+3 Equivalent to x=x%(y+3), Don't write it wrong x=x%y+3.
5、 ... and 、 Assignment expression
The function of assignment expression is to assign the value of an expression to a variable , Therefore, the assignment expression has the dual functions of calculation and assignment .
The process of solving the assignment expression is :
① Find “ expression ” Value ,② Assign to the variable to the left of the assignment operator . Since it's an expression , There should be a value , The value of the expression is equal to the value of the left variable after assignment .
The left side of the assignment operator should be a modifiable value “ The left value ”(left value, Shorthand for lvalue).
The expression that can appear to the right of the assignment operator is called “ Right value ”(right value, Shorthand for rvalue).
Be careful : Not all forms of data can be used as lvalues , Lvalue should be storage space and can be assigned . Variables can be used as lvalues , And arithmetic expression a+b Can't be used as an lvalue , Constants cannot be used as lvalues .
a=b=c=5 Expression value is 5,a,b,c Values are 5
a=5+(c=6) Expression value is 11,a The value is 11,c The value is 6
a=(b=4)+(c=6) Expression value is 10,a The value is 10,b be equal to 4,c be equal to 6
a=(b=10)/(c=2) Expression value is 5,a be equal to 5,b be equal to 10,c be equal to 2
a=(b=3*4) Expression value is 12,a,b Values are 12
The assignment expression makes the assignment operation not only appear in the assignment statement , And it can appear in other statements ( Such as output statement 、 Loop statement, etc )
Such as : printf("%d", a=b);
If b The value of is 3, The output a Value ( Also an expression a=b Value ) by 3. In a printf Function completes the dual functions of assignment and output .
6、 ... and 、 Type conversion during assignment
If the types on both sides of the assignment operator are the same , Then assign the value directly .
If the types on both sides of the assignment operator are inconsistent , But when they are all basic types , Type conversion is required during assignment . Type conversion is performed automatically by the system , The rule of transformation is :
Convert floating point data ( Including single 、 Double precision ) When you assign an integer variable , First round the floating-point number , That is, the decimal part is discarded , Then give an integer variable .
Assign integer data to a single 、 Double precision variable , Constant value , But it's stored in a variable as a floating point number .
Will a double Type data is assigned to float variable , First, convert double precision numbers to single precision numbers , That is to say, only 6~7 Significant digits , Store in float Type variable 4 In bytes . It should be noted that the size of the double precision value cannot exceed float The range of values for a variable of type ; Will a float Type data is assigned to double Type variable , Constant value , In memory with 8 Byte store , The number of significant digits extends to 15 position .
When character data is assigned to an integer variable , The ASCII Code assigned to integer variables .
When an integer with more bytes is assigned to an integer or character variable with less bytes , Only send its low byte intact to the assigned variable ( That is to say “ truncation ”).
边栏推荐
- Vs 2019 configure tensorrt to generate engine
- I2C 子系统(二):I3C spec
- MySql實戰45講【SQL查詢和更新執行流程】
- Force deduction ----- the minimum path cost in the grid
- MySQL practice 45 lecture [transaction isolation]
- labelimg生成的xml文件转换为voc格式
- Yolov5 project based on QT
- idea 加载不了应用市场解决办法(亲测)
- Notifydatasetchanged not applicable to recyclerview - notifydatasetchanged not working on recyclerview
- 左连接,内连接
猜你喜欢

Spark on yarn资源优化思路笔记

I2C 子系统(一):I2C spec

VS 2019 配置tensorRT生成engine

分布式事务

MySql实战45讲【全局锁和表锁】

C language beginner level - pointer explanation - paoding jieniu chapter

Pytorch轻量级可视化工具wandb(local)

Opengauss database development and debugging tool guide

Distributed transaction

Gavin teacher's perception of transformer live class - rasa project's actual banking financial BOT Intelligent Business Dialogue robot architecture, process and phenomenon decryption through rasa inte
随机推荐
[error record] the parameter 'can't have a value of' null 'because of its type, but the im
Pat class B "1104 forever" DFS optimization idea
MySql实战45讲【索引】
将时间戳转为指定格式的时间
Reset or clear NET MemoryStream - Reset or Clear . NET MemoryStream
The process of connecting MySQL with docker
二维数组中的元素求其存储地址
Force deduction ----- the minimum path cost in the grid
PAT乙级常用函数用法总结
Last update time of all sqlserver tables
Pat class B common function Usage Summary
docker安装mysql
What happens between entering the URL and displaying the page?
MySql實戰45講【SQL查詢和更新執行流程】
Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
TCP handshake three times and wave four times. Why does TCP need handshake three times and wave four times? TCP connection establishes a failure processing mechanism
分布式事务
Use of El tree search method
I2C subsystem (IV): I2C debug
MySql实战45讲【事务隔离】