当前位置:网站首页>4、 C language operators
4、 C language operators
2022-07-28 14:53:00 【Rock magnon】
List of articles
1、 Operator classification
- Arithmetic operator
- %: Modulo operators , The remainder after division , Integer only , It can't be a decimal , The result symbol depends on % The symbol on the left
- Relational operator
- be equal to 、 It's not equal to 、 Greater than 、 Less than 、 Greater than or equal to 、 Less than or equal to
- Logical operators
- &&: Logic and computation
- ||: Logic or operation
- !: Logical nonoperator
- An operator
- &: Bitwise AND
- |: Press bit or
- ^: Exclusive or operation
- ~: Reverse operation
- ~1 = -2
- ~0 = -1
- <<: Shift left operator , The right to repair 0
- />>: Shift right operator , Positive left to fill 0, Negative left to fill 1
- Assignment operator
| Operator | effect |
|---|---|
| = | c = a+b |
| c+=a | c=c+a |
| c-=a | c=c-a |
| c*=a | c=c*a |
| c/=a | c=c/a |
| c%=a | c=c%a |
| c<<=2 | c=c<<2 |
| c>>=2 | c=c>>2 |
| c&=2 | c=c&2 |
| c^=2 | c=c^2 |
| c|=2 | c=c|2 |
- Miscellaneous operators
- sizeof(): Returns the size of the variable
- &: Return the address of the variable
- *: Point to a variable
- ?:: Conditional expression , Ternary operator
2、 Detailed explanation of operation
1.a++ and ++a The difference between
- Code implementation :
#include<stdio.h> int main(){ int c; int a = 10; c = a++;//c As the result of the 10 printf(" Operation after assignment :%d\n",c); a = 10; c = ++a;//c As the result of the 11 printf(" Evaluate first and then assign :%d",c); } - Running results :
Operation after assignment :10 Evaluate first and then assign :11
2. An operator
- Code implementation :
#include<stdio.h> #include<stdlib.h> void binary(int x){ int b,i,k = 0; int remainder[30]; while (x != 0) { b = x/2; k++; remainder[k] = x - b*2; x = x/2; } for(i = k;i >= 1;i--){ printf("%d",remainder[i]); } printf("\n"); } int main(){ unsigned int a = 60; //00111100 unsigned int b = 13; //00001101 int c = 0; c = a & b; printf("a,b Bitwise AND :"); binary(c); c = a | b; printf("a,b Press bit or :"); binary(c); c = a ^ b; printf("a,b Bitwise XOR :"); binary(c); c = ~a; printf("a Take the opposite :"); binary(c); printf("a Take the opposite :%d\n",c); c = a << 2; printf("a Move two places to the left :"); binary(c); c = a >> 2; printf("a Move two places to the right :"); binary(c); } - Running results :
a,b Bitwise AND :1100 a,b Press bit or :111101 a,b Bitwise XOR :110001 a Take the opposite :-1-1-1-10-1 a Take the opposite :-61 a Move two places to the left :11110000 a Move two places to the right :1111
3. Miscellaneous operators
- Code implementation :
#include<stdio.h> int main(){ int a = 4; short b; double c; int *ptr;// Define a pointer printf("a Size :%ld\n",sizeof(a)); ptr = &a;// take a Address assigned to ptr printf("*ptr Value :%d\n",*ptr);// Take the value corresponding to the address a = 10; b = (a == 10) ? 20 : 30;// Ternary operator printf("b Value :%d",b); } - Running results :
a Size :4 *ptr Value :4 b Value :20
4. In calculator , Negative numbers exist in the form of complements of their positive values
- Source code :0001
- Inverse code :1110
- Complement code : Counter code plus 1 1111
5. ~ operation
- effect : According to the not
- Code implementation :
#include<stdio.h> #include<stdlib.h> int main(){ int b = 13; //00001101 printf("%x",~b); } - Running results :
fffffff2 //11110010
边栏推荐
- [线程安全问题] 多线程到底可能会带来哪些风险?
- Swiftui layout - alignment
- C # 7 methods to obtain the current path
- SwiftUI 布局 —— 尺寸( 下 )
- [Tanabata] Tanabata lonely little frog research edition? The final chapter of Tanabata Festival!
- Some problems encountered in the development of Excel VBA, solutions, and continuous updates
- 用 Table 在 SwiftUI 下创建表格
- C language related programming exercises
- How to make the characters in the photos laugh? HMS core video editing service one click smile function makes people smile more naturally
- RPC (remote procedure call protocol) telecommunication framework
猜你喜欢
C # 7 methods to obtain the current path

国产数据库的红利还能“吃”多久?

Floating point data type in C language (did you learn to waste it)

VTK annotation class widget vtkborderwidget

When Xcode writes swiftui code, it is a small trap that compiles successfully but causes the preview to crash

Product Manager

C语言库函数getchar()怎么使用

Focus on differentiated product design, intelligent technology efficiency improvement and literacy education around new citizen Finance

Penguin side: why not recommend using select *?

围绕新市民金融聚焦差异化产品设计、智能技术提效及素养教育
随机推荐
BGP experiment
Pointers and arrays (7)
Redis-Redis在Jedis中的使用
UI开发中所遇到的各种坑
Cv:: mat conversion to qimage error
8、 Picker usage drop-down box selection effect
Raspberry pie foundation | summarize and record some operations in the learning process of raspberry pie
1st pre class exercise
JS instantiation method
国产数据库的红利还能“吃”多久?
Hand in hand from 0 to a "Nuggets special attention" Google plug-in, 5000 words detailed vue3 responsive principle, the advantages, disadvantages and choices of several cache read-write schemes, flyin
Interviewer: what are the usage scenarios of ThreadLocal? How to avoid memory leakage?
Third class exercise
Four basic data types
The 35 required questions in MySQL interview are illustrated, which is too easy to understand
Simple data analysis using Weka and excel
Thoughts on the construction of some enterprise data platforms
The third pre class exercise
Create a table under swiftui with table
多线程顺序运行有几种方法?