当前位置:网站首页>C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions
2022-07-03 03:14:00 【ihan001】
List of articles
One 、 Operators and Expressions

Two 、 Common arithmetic operators :

Be careful :
1. Divide two real numbers , The result is a double precision real number
2. The result of dividing two integers is an integer
3.% For integers only
3、 ... and 、 Self increasing (++) Self reduction (–) Operator
++i,–i In the use of i Before , First of all i The value of the add / reduce 1
i++,i-- In the use of i after , send i The value of the add / reduce 1
++i It's to execute first i=i+1, Reuse i Value ; and i++ Use first i Value , Re execution i=i+1.
int i=3,j;
j=++i; //i The value of becomes 4, Reassign to j,j The value of is 4
int i=3;
printf(“%d”,++i); // Output 4
int i=3,j;
j=i++; // First the i Value 3 Assign to j,j The value of is 3, then i Turn into 4
int i=3;
printf(“%d”,i++); // Output 3
Four 、 Type conversion ( a key )
Automatic type conversion
1.+、-、*、/ One of the two numbers in the operation is float or double type , The result is double type , Because the system will all float Type data are converted to double type , And then you do the math .
2. If int Type and float or double Type of data , The first int The type and float Type data is converted to double type , And then you do the math , The result is double type .
3. character (char) Type data and integer data , That is to put the character ASCII Code and integer data . If character data and real data are operated , Then the ASCII Code conversion to double Type data , And then you do the math .
give an example 1:
int i=3;
float f=2.5;
double d=7.5;
printf("%lf",10+'a'+i*f-d/3);
10+‘a’+if-d/3
① Conduct 10+′a′ Arithmetic ,′a′ The value of is an integer 97, The result of operation is 107.
② because “” Than “+” High priority , to if Arithmetic . First the i And f All turned into double type , The result of operation is 7.5,double type .
③ Integers 107 And if Add the products of . Integer first 107 Convert to double , The sum is 114.5,double type .
④ Conduct d/3 Arithmetic , First the 3 convert to double type ,d/3 The result is 2.5,double type .
⑤ take 10+′a′+i*f Result 114.5 And d/3 The business of 2.5 Subtracting the , The result is 112.0,double type .
give an example 2:
Given a capital letter , Output in lowercase letters is required .
#include <stdio.h>
int main()
{
char c1,c2;
c1='A'; // The character ′A′ Of ASCII Put the code in c1 variable
c2=c1+32; // Get the characters ′a′ Of ASCII Code , Put it in c2 variable
printf("%c\n",c2); // Output c2 Value , Is a character
printf("%d\n",c2); // Output c2 Value , Is the character ′a′ Of ASCII Code
return 0;
}
Cast : When automatic type conversion cannot achieve its purpose , You can use cast .
Cast operators
( Type name )( expression )
(double)a take a convert to double type
(int)(x+y) take x+y The value of is converted to int type
(float)(5%3) take 5%3 The value of is converted to float type
(int)x+y Only will x Convert to integer , Then with y Add up
int a; float x,y;double b;
a=(int)x
Perform forced type operation (int)x And then I got a int Temporary value of type , Its value is equal to x The integral part of , Give it to a, Be careful x The value and type of have not changed , Still float type . The temporary value no longer exists after assignment .
边栏推荐
猜你喜欢

用docker 連接mysql的過程

Three. JS local environment setup

I2C 子系統(四):I2C debug

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
![MySQL practice 45 [SQL query and update execution process]](/img/cd/3a635f0c3bb4ac3c8241cb77285cc8.png)
MySQL practice 45 [SQL query and update execution process]

为什么线程崩溃不会导致 JVM 崩溃

敏捷认证(Professional Scrum Master)模拟练习题-2

TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制

Anhui University | small target tracking: large-scale data sets and baselines

Docker install MySQL
随机推荐
Use of check boxes: select all, deselect all, and select some
docker安装redis
监听对象中值变化及访问
Solve high and send system Currenttimemillis Caton
PAT乙级“1104 天长地久”DFS优化思路
MySQL practice 45 lecture [transaction isolation]
Last update time of all sqlserver tables
敏捷认证(Professional Scrum Master)模拟练习题-2
【PyG】理解MessagePassing过程,GCN demo详解
com. fasterxml. jackson. databind. Exc.invalidformatexception problem
Vs 2019 configuration du moteur de génération de tensorrt
[algebraic structure] group (definition of group | basic properties of group | proof method of group | commutative group)
Agile certification (professional scrum Master) simulation exercise-2
Pat class B common function Usage Summary
Change cell color in Excel using C - cell color changing in Excel using C
模糊查询时报错Parameter index out of range (1 > number of parameters, which is 0)
3D drawing example
@Accessors注解作用指定前缀遵守驼峰命名
文件重命名
[Fuhan 6630 encodes and stores videos, and uses RTSP server and timestamp synchronization to realize VLC viewing videos]