当前位置:网站首页>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
边栏推荐
- Data center basic network platform
- CA Zhouji - the first lesson in 2022 rust
- Redis-跳表
- Main steps of system test
- How to compare two or more distributions: a summary of methods from visualization to statistical testing
- 华大4A0GPIO设置
- Virtual private network foundation
- LeetCode Algorithm 剑指 Offer II 027. 回文链表
- Ideal L9, new trend of intelligent cockpit
- Basic principles of spanning tree protocol
猜你喜欢

Redis hop table

Raspberry pie preliminary use

NiO zero copy

What aspects should we start with in the feasibility analysis of dry goods?

The usage difference between isempty and isblank is so different that so many people can't answer it

Panorama of enterprise power in China SSD industry

Layer 2 and layer 3 forwarding principle based on VLAN

NIO、BIO、AIO

Genesis公链与美国一众加密投资者齐聚Consensus 2022

Online filing process
随机推荐
Basic principles of spanning tree protocol
Docker installs MySQL 8.0. Detailed steps
In the era of full programming, should I give up this road?
socket done
CA Zhouji - the first lesson in 2022 rust
Embedded development: tips and tricks -- clean jump from boot loader to application code
【軟件工程】期末重點
Data communication and physical network
2022-06-10 工作记录--JS-获取到某一日期N天后的日期
Learn more about the practical application of sentinel
Web攻击之CSRF和SSRF
NIO多路复用之Selector的使用
Leetcode: calculate the number of elements less than the current element on the right (sortedlist+bisect\u left)
堆內存分配的並發問題
DX 的 HLSL 和 GL 的 GLSL的 矩阵构建的行列区别
Visitor tweets tell you which groups are consuming blind boxes
Online filing process
Principles of Ethernet port mirroring, link aggregation and VLAN Technology
使用Aggregated APIServer扩展你的kubernetes API
Fanuc robot_ Introduction to Karel programming (1)