当前位置:网站首页>C language operators and expressions
C language operators and expressions
2022-06-24 22:41:00 【Tengban monster】
Catalog
Assignment operator 、 Assignment expression
Arithmetic operator 、 Arithmetic expressions
Auto increment and auto decrement operator
Preface
Operators are used to process data . Using operators to connect variables and constants conforms to C Expressions of linguistic grammar rules are called expressions . Single constant 、 A variable or function is a simple expression .
It is divided according to the number of operands carried by the operator ,C There are three categories of operators in languages :
Monocular operator : An operator with only one operand . Such as :++ Operator .
Binocular operator : Operator with two operands . Such as :+、-、*、/、% Operator .
Ternary operator : Operator with three operands . Such as :? Operator .
Assignment operator 、 Assignment expression
1. Assignment operator
Symbol : =
function : Assign the value of the expression on the right to the variable on the left . The left and right sides here are not interchangeable .
Binocular operator : There are operands on both sides .
for example :
int a,b,c;
a=1314;//a=1314
b=a;//b=1314
c=a+b;//c=26282. Assignment expression
Let's look at an example :
a=520Be careful : Expressions have values , The value of the assignment expression is the value of the assigned variable . The above example a=520 The value of this assignment expression is a Value 520.
3. Assignment statement
C Language policy , Any expression with a semicolon at the end becomes a statement .
So assignment expression plus semicolon is assignment statement .
Look at the example again :
a=365;4. usage
Continuous assignment : Right binding , That is, to operate from right to left .
Look at examples :
a=b=c=d=666;Cast cast character
1. Automatic conversion
When = When the data types on both sides are different ,C Language will make = The data type of the expression value on the right becomes = The data type of the variable on the left .
Look at examples :
int a=3.65;//a=32. Coercive transformation
Change if you want to :
float a=1.79,b=2.1;that (int)a The value is 1, Yes , It's rounding down ,(int)(a+b) Then it is a+b The result turns into int type , Its value is 3.
Arithmetic operator 、 Arithmetic expressions
1. Arithmetic operator
Symbol : + - * / %
function : I believe you can add (+)、 reduce (-)、 ride (*)、 except (/) You can understand , Remainder (%) What is it? ?
According to my habit , Let's take a look at the examples first :
int a=10%3;//a=1
int b=9%3;//b=0
It is often used in the follow-up study , There is another thing called mold taking , These two mean the same , Is the remainder of the division of two numbers . The remainder is very easy to use , It's a skill job .
Be careful :C Language policy , The quotient of the division of two integers is still an integer , Rounding down .
for example :5/2 The result is 2, If you want to get 2.5, Should be written as 5.0/2 or 5/2.0.
Be careful :% It can only be used for integer operations .
2. Arithmetic expressions
An expression whose operators are all arithmetic operators is called an arithmetic expression . I believe everyone can understand .
Auto increment and auto decrement operator
Symbol : ++ - -
seeing the name of a thing one thinks of its function , Look at the example , Feel for yourself :
int i=j=k=l=6;
i++;//i=7
j--;//j=5
++k;//k=7
--l;//l=5Okay , I believe you should have doubts in your mind . Here's an explanation :
Prepositive operations :++i、--i: Increase or decrease before operation .
Post operation :i++、i--: Calculate first and then increase or decrease .
Look at examples :
int i=j=k=l=6,look;
look=i++;//look=6,i=7
look=j--;//look=6,j=5
look=++k;//look=7,k=7
look=--l;//look=5,l=5Be careful :++ and -- Operators can only be used with variables , Cannot be used for constants and expressions .
Two + And two - There is no space between .
Auto increment and auto decrement are often used in loop statements .
You cannot use... On a variable consecutively , Such as ++i++ It's illegal. .
sizeof Operator
Symbol :sizeof
function : Get the memory occupied by variables and data types ( Number of bytes ).
Be careful :sizeof in size and of There is no space between .
Compound assignment operator
Symbol :+=、-=、*=、/=、%=、&=、|=、^=、<<=、>>=
function : See the following example :
a+=1 Equivalent to a=a+1
a*=2 Equivalent to a=a*2
边栏推荐
- CSRF and SSRF for web attacks
- Data center basic network platform
- 堆內存分配的並發問題
- Main steps of system test
- Power system | IEEE paper submission process
- Visitor tweets tell you which groups are consuming blind boxes
- Description of transparent transmission function before master and slave of kt6368a Bluetooth chip, 2.4G frequency hopping automatic connection
- 华大04a工作模式/低功耗模式
- Idea global search replace shortcut key
- NIO、BIO、AIO
猜你喜欢

Uncover the secret of station B. is it true that programmers wear women's clothes and knock code more efficiently?

华大04a工作模式/低功耗模式

Servlet details

Description of software version selection of kt6368a Bluetooth dual-mode transparent chip

NiO zero copy
How to solve the problem that the computer suddenly can't connect to WiFi

See how sparksql supports enterprise level data warehouse

Principles of Ethernet port mirroring, link aggregation and VLAN Technology

Genesis public chain and a group of encryption investors in the United States gathered in consensus 2022
![[QT] QT event handling](/img/48/14a5491307fee1c99434d6cb308337.jpg)
[QT] QT event handling
随机推荐
Huada 04A operating mode / low power consumption mode
结合源码剖析Oauth2分布式认证与授权的实现流程
Unable to use the bean introduced into the jar package
Certificate photo processing
Chapter 10 project communication management
A pit in try with resources
结构体的内存对齐
[QT] QT event handling
Virtual private network foundation
ThreadLocal内存泄漏问题
Fanuc robot_ Introduction to Karel programming (1)
2022-06-10 work record --js- obtain the date n days after a certain date
Heavyweight! Fada is listed as a "specialized and new" enterprise
OA system -- save the verification code to session
Problem solving - nested lists
故障安全移动面板KTP900F Mobile下载程序提示无法下载,目标设备正在运行或未处于传输模式的解决办法
Information update on automatic control principle
Idea close global search box
LeetCode Algorithm 剑指 Offer II 027. 回文链表
Docker installs redis-5.0.12. Detailed steps