当前位置:网站首页>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
边栏推荐
- linux安装mysql
- js的实例化方式
- Product Manager
- Raspberry pie foundation | summarize and record some operations in the learning process of raspberry pie
- OKR and grad
- SwiftUI 4.0 的全新导航系统
- I am using a blog creation tool
- Afnetworking crash course
- How to effectively conduct the review meeting (Part 1)?
- Interviewer: what are the usage scenarios of ThreadLocal? How to avoid memory leakage?
猜你喜欢

Raspberry pie foundation | summarize and record some operations in the learning process of raspberry pie

Getting started with scottplot tutorial: getting and displaying values at the mouse

树莓派基础 | 总结记录树莓派学习过程中的一些操作

Many "double first-class" universities have launched the research guarantee and prediction name!

The 35 required questions in MySQL interview are illustrated, which is too easy to understand

Installing redis in Linux

【七夕】七夕孤寡小青蛙究极版?七夕节最终章!

Hcip day 12

使用Weka与Excel进行简单的数据分析

It's so hot that solar power can't take off? Hello, head
随机推荐
35道MySQL面试必问题图解,这样也太好理解了吧
Why can the anonymous functions of JQ access the methods inside
Digital transformation security issues occur frequently, and Shanshi Netcom helps build a digital government
Excel VBA 免密查看VBE加密代码
Copy excel row to specified row
Swiftui layout - alignment
C language: mathematical method of converting decimal system into binary system
Core Data 是如何在 SQLite 中保存数据的
C语言库函数getchar()怎么使用
Hcip day 10
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
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
C language exercises
C# 读取ini文件、键值对操作
C语言实现简单学生成绩管理系统的方法
Hcip day 11
Thoughts on the construction of some enterprise data platforms
Several methods of opening URL in swiftui view
SwiftUI 布局 —— 对齐