当前位置:网站首页>The third level of C language punch in
The third level of C language punch in
2022-07-06 02:16:00 【HTTPS 443୧⍤⃝】
One 、 Cast expression
form :( Type name ) expression
function : Converts the value of an expression to the specified data type
(double) 1/2 The value of is 0.5 ( As mentioned in the last section 1/2 It's two integers Should the 0 Because there is a double, The value is decimal 0.5, amount to (double)1/2 Equivalent to 1.0/2)
The level of cast takes precedence over division
This table describes the transformation rules more vividly
Two 、 Assignment expression
form : Variable name = expression
On the left is a variable name , Get the value of an expression on the right , Assign the value of the expression to a variable , Its combination is
From right to left , Its priority is only higher than comma operator . The value of the assignment expression is the new value obtained by the leftmost variable .
Simply put, it's the left A variable , On the right is an equation . such as :a=2+7/3
(1) Compound assignment expression
such as n+=1 Equivalent to n=n+1
n*=m+3 Equivalent to n=n*(m+3)
Yes : = += -= /= %= &= ^= wait associativity : From right to left
(2) Type conversion in assignment operation
int x; x=6.5; //x Integers 6, Here is a transformation , Convert to be consistent with the type of variable double y; y=6; //y by 6.0, Here is a transformation , Convert to be consistent with the type of variable
3、 ... and 、 Auto increment and auto decrement operator
Self adding 、 The subtraction operator is ++ and --. Self adding ( reduce ) Operator in front , First increase ( reduce ) After use ; Self adding ( reduce ) Operator after , Use first and then increase ( reduce ). The combination direction of operators is from right to left ,-k++ Equivalent to -(k--).
Self adding ( reduce ) There are often two operations in the operation : Calculate the value of the expression and the value of the variable .
set up k=3, Calculate the value of the following assignment expression and calculate the value of the variable
expression x Value k Value The value of the assignment expression x=k++ 3 4 3 x=++k 4 4 4 x=k-- 3 2 3 x=--k 2 2 2 As can be seen from the table :++ Must make k increase 1,-- Must make k reduce 1, Because it is an assignment expression , therefore x The value of is interlinked with the value of the expression
Four 、 Comma operators and comma expressions
form : expression 1, expression 2,....., expression n
Combination direction : From left to right
Operational rules : So let's evaluate the expression 1 Value , And then evaluate the expression 2 Value , And then calculate the expression 3 Value ,..... Finally, calculate the expression n Value , expression n The value of is the value of the entire comma expression
The comma expression has the lowest priority , Lower than assignment
int x=8,y=12,z=14 x++,y=z++,z=++x; y=x%z--; // Last x=10 y=0,z=9answer :
The original x=8 You can see that from the top Yes x++ Add a ,++x Once again, , Total increase 2 Time , Namely 8+2=10
The original y=12 y=X%z-- here x=10 z=10 because z=++x ,z-- Is the suffix with the previous value 10 To participate in the calculation , therefore 10%10=0 ,y Is equal to 0
The original z=14 First, y=z++ ,z=15 also z=++x ,z be equal to 10, Last z-- Say with z=9
Answer of last issue :
#include<stdio.h>
void main()
{
double a,b,c; // Define three real numbers
double sum,aver; //sum Storage and ,aver Store the average
scanf("%lf%lf%lf",&a,&b,&c); // Input 3 A real number
sum=a+b+c; // Calculation 3 Sum of numbers
aver=(a+b+c)/3; // Calculation 3 The average of the numbers
getchar();
getchar();
}This assignment
1. Enter the of the triangle 3 Strip side length , Find the area of three triangles ( Query the formula on the Internet , I will use the square function sqrt, File header is required math.h)
2. Input 2 Number , In exchange for 2 The value of the number
for example : x=2 ,y=3 After exchanging x=3,y=2
边栏推荐
- 好用的 JS 脚本
- 论文笔记: 图神经网络 GAT
- 阿裏測開面試題
- Xshell 7 Student Edition
- genius-storage使用文档,一个浏览器缓存工具
- How to use C to copy files on UNIX- How can I copy a file on Unix using C?
- Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
- Redis list
- [eight part essay] what is the difference between unrepeatable reading and unreal reading?
- 一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
猜你喜欢

leetcode3、實現 strStr()

NumPy 数组索引 切片

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

Using SA token to solve websocket handshake authentication

Using SA token to solve websocket handshake authentication

How does redis implement multiple zones?

RDD conversion operator of spark

Use the list component to realize the drop-down list and address list

同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
随机推荐
genius-storage使用文档,一个浏览器缓存工具
Global and Chinese markets of general purpose centrifuges 2022-2028: Research Report on technology, participants, trends, market size and share
【clickhouse】ClickHouse Practice in EOI
Leetcode sum of two numbers
Sword finger offer 12 Path in matrix
[solution] add multiple directories in different parts of the same word document
模板_求排列逆序对_基于归并排序
Formatting occurs twice when vs code is saved
500 lines of code to understand the principle of mecached cache client driver
Compact lidar global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
模板_快速排序_双指针
How to use C to copy files on UNIX- How can I copy a file on Unix using C?
怎么检查GBase 8c数据库中的锁信息?
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
[solution] every time idea starts, it will build project
3D drawing ()
1. Introduction to basic functions of power query
[eight part essay] what is the difference between unrepeatable reading and unreal reading?
[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
