当前位置:网站首页>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 .
边栏推荐
- Variable declarations following if statements
- MySQL practice 45 [SQL query and update execution process]
- 【PyG】理解MessagePassing过程,GCN demo详解
- Find the storage address of the elements in the two-dimensional array
- VS 2019配置tensorRT
- 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
- Distributed transaction
- [error record] the parameter 'can't have a value of' null 'because of its type, but the im
- 分布式事务
- Parameter index out of range (1 > number of parameters, which is 0)
猜你喜欢

I2C 子系统(三):I2C Driver

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

MySql实战45讲【索引】

MySql实战45讲【事务隔离】

docker安装redis

The idea cannot be loaded, and the market solution can be applied (pro test)

Docker install redis

Force deduction ----- the minimum path cost in the grid

I2C subsystem (III): I2C driver

LVGL使用心得
随机推荐
Unity3d RPG implementation (medium)
VS克隆时显示403错误
Vs 2019 configuration tensorrt
MySQL practice 45 lecture [transaction isolation]
Are there any recommended term life insurance products? I want to buy a term life insurance.
com. fasterxml. jackson. databind. Exc.invalidformatexception problem
用docker 連接mysql的過程
为什么线程崩溃不会导致 JVM 崩溃
模型转换onnx2engine
How to limit the size of the dictionary- How to limit the size of a dictionary?
二进制流转换成字节数组
How to select the minimum and maximum values of columns in the data table- How to select min and max values of a column in a datatable?
Introduction to cron expression
com.fasterxml.jackson.databind.exc.InvalidFormatException问题
Nasvit: neural architecture search of efficient visual converter with gradient conflict perception hypernetwork training
你真的懂继电器吗?
Last update time of all sqlserver tables
labelimg生成的xml文件转换为voc格式
复选框的使用:全选,全不选,选一部分
The idea cannot be loaded, and the market solution can be applied (pro test)