当前位置:网站首页>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 .
边栏推荐
- Spark on yarn资源优化思路笔记
- PAT乙级“1104 天长地久”DFS优化思路
- com. fasterxml. jackson. databind. Exc.invalidformatexception problem
- Pytorch轻量级可视化工具wandb(local)
- [error record] the parameter 'can't have a value of' null 'because of its type, but the im
- docker安装redis
- [Fuhan 6630 encodes and stores videos, and uses RTSP server and timestamp synchronization to realize VLC viewing videos]
- Agile certification (professional scrum Master) simulation exercise-2
- Unity3d RPG implementation (medium)
- 模糊查詢時報錯Parameter index out of range (1 > number of parameters, which is 0)
猜你喜欢
随机推荐
3D drawing example
umi 路由拦截(简单粗暴)
About HTTP cache control
Use of El tree search method
Are there any recommended term life insurance products? I want to buy a term life insurance.
@Accessors注解作用指定前缀遵守驼峰命名
Reset or clear NET MemoryStream - Reset or Clear . NET MemoryStream
[combinatorics] Application of exponential generating function (multiple set arrangement problem | different balls in different boxes | derivation of exponential generating function of odd / even sequ
C#通用接口调用
Agile certification (professional scrum Master) simulation exercise-2
Nasvit: neural architecture search of efficient visual converter with gradient conflict perception hypernetwork training
vfork执行时出现Segmentation fault
左连接,内连接
How to make backgroundworker return an object
VS克隆时显示403错误
Application of derivative in daily question
为什么线程崩溃不会导致 JVM 崩溃
[shutter] monitor the transparency gradient of the scrolling action control component (remove the blank of the top status bar | frame layout component | transparency component | monitor the scrolling
Solve high and send system Currenttimemillis Caton
node 开启服务器