当前位置:网站首页>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 .
边栏推荐
- MySQL practice 45 lecture [row lock]
- el-tree搜索方法使用
- MySql实战45讲【SQL查询和更新执行流程】
- Use of check boxes: select all, deselect all, and select some
- Edit and preview in the back pipe to get the value writing method of the form
- How to use asp Net MVC identity 2 change password authentication- How To Change Password Validation in ASP. Net MVC Identity 2?
- Reset or clear NET MemoryStream - Reset or Clear . NET MemoryStream
- I2C 子系统(二):I3C spec
- docker安装mysql
- Spark on yarn resource optimization ideas notes
猜你喜欢

你真的懂继电器吗?

Yiwen takes you to know ZigBee

Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!

900W+ 数据,从 17s 到 300ms,如何操作

从C到Capable-----利用指针作为函数参数求字符串是否为回文字符

Vs Code configure virtual environment

【PyG】理解MessagePassing过程,GCN demo详解

Sous - système I2C (IV): débogage I2C

Why does thread crash not cause JVM crash

函数栈帧的创建与销毁
随机推荐
Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception
Agile certification (professional scrum Master) simulation exercises
I2C subsystem (I): I2C spec
Can I use read-only to automatically implement properties- Is read-only auto-implemented property possible?
Hi3536C V100R001C02SPC040 交叉编译器安装
Nasvit: neural architecture search of efficient visual converter with gradient conflict perception hypernetwork training
The base value is too large (the error is marked as "08") [duplicate] - value too great for base (error token is'08') [duplicate]
@Accessors annotation function specifies that the prefix follows the hump naming
VS 2019安装及配置opencv
I2C subsystem (IV): I2C debug
[pyg] understand the messagepassing process, GCN demo details
The idea setting code is in UTF-8 idea Properties configuration file Chinese garbled
Docker install redis
为什么线程崩溃不会导致 JVM 崩溃
复选框的使用:全选,全不选,选一部分
Left connection, inner connection
Bigvision code
I2C subsystem (II): I3C spec
Change cell color in Excel using C - cell color changing in Excel using C
销毁Session和清空指定的属性