当前位置:网站首页>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 .
边栏推荐
- Idea format code idea set shortcut key format code
- How do you adjust the scope of activerecord Association in rails 3- How do you scope ActiveRecord associations in Rails 3?
- Use of El tree search method
- labelme标记的文件转换为yolov5格式
- 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
- [Fuhan 6630 encodes and stores videos, and uses RTSP server and timestamp synchronization to realize VLC viewing videos]
- TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制
- 文件重命名
- [combinatorics] Application of exponential generating function (multiple set arrangement problem | different balls in different boxes | derivation of exponential generating function of odd / even sequ
- 【AI实战】应用xgboost.XGBRegressor搭建空气质量预测模型(一)
猜你喜欢

Three. JS local environment setup

MySql实战45讲【索引】

别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!

Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf

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

Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception

docker安装mysql

Idea format code idea set shortcut key format code

Le processus de connexion mysql avec docker

VS code配置虚拟环境
随机推荐
Docker install MySQL
labelimg生成的xml文件转换为voc格式
How do you adjust the scope of activerecord Association in rails 3- How do you scope ActiveRecord associations in Rails 3?
Spark on yarn resource optimization ideas notes
Reset or clear NET MemoryStream - Reset or Clear . NET MemoryStream
Bigvision code
3D drawing example
Destroy the session and empty the specified attributes
How to use asp Net MVC identity 2 change password authentication- How To Change Password Validation in ASP. Net MVC Identity 2?
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
node 开启服务器
Parameter index out of range (1 > number of parameters, which is 0)
Are there any recommended term life insurance products? I want to buy a term life insurance.
C# WebRequest POST模式 ,基于“Basic Auth”口令认证模式,使用multipart/form-data方式上传文件及提交其他数据
Creation and destruction of function stack frame
Sous - système I2C (IV): débogage I2C
Unity3d RPG implementation (medium)
Can I use read-only to automatically implement properties- Is read-only auto-implemented property possible?
PAT乙级“1104 天长地久”DFS优化思路
I2C subsystem (III): I2C driver