当前位置:网站首页>C language operators and input and output
C language operators and input and output
2022-07-28 20:00:00 【Embedded Xiaobai aspires to be a boss】
- Operator
- An operator
- Input and output
- Control statement
1、 Operator
Single calculation, moving customs and , Exclusive or logic
Monocular operator 、 Arithmetic operator 、 Move left, move right 、 Relational operator 、 Bitwise AND , Exclusive or 、 Press bit or 、 Logical operators 、 Conditional operator 、 assignment
1.1 Arithmetic operator
+、-、*、/、%、++、--
Be careful :% Can't be used with floating point numbers
++ before :++a Add it first , To assign a value
++ After :a++ Assign first , Self adding
1.2 Relational operator
>、<、>=、<=、==、!=
Be careful :0 < a < 5 //error
Equal sign writing :
1.3 Logical operators
&& 、|| 、 !
expression 1 && expression 2
&& The law of truncation : One is false , The result is false , If the previous one is false , There will be no operation later
expression 1 || expression 2
|| The law of truncation : One is true , That's true , The previous one is true , There will be no more operations later
Case study 2:
1.4 sizeof Operator
sizeof( data type ) or sizeof( Variable name )
1.5 Ternary operator
expression 1? expression 2: expression 3
Judging expressions 1 Is the value of true , If set up , Expression 2 As the value of the entire expression , otherwise , Expression 3 As the value of the entire expression
1.6、 The comma operator
expression 1, expression 2, expression 3 …… expression n
Execute each expression from left to right , Expression n As the value of the entire expression
Be careful : The comma operator has the lowest priority , Use parentheses
Case study 1:
- set up int i=2,j=3,k=4,a=4,b=5,c=3;, Then execute the expression (a=i<j)&&(b=j>k)&&(c=i,j,k) after ,c The value is (3)
2、 An operator
&、|、~、^、<<、>>
2.1 And operation (&)
1101 0011
& 0110 1110
0100 0010
Case study : take 1101 0011 Of 0~2 A reset
1101 0011
& 1111 1000 (~0000 0111)
1101 0000
2.2 Or operations
1010 0101
| 1110 1011
1110 1111
Case study : take 1010 0101 Of 3~5 A into 101
1010 0101
& 1100 0111
1000 0101
| 0010 1000
1010 1101
2.3 Take the opposite
~1010 1111 --->0101 0000
2.4 Exclusive or
Same as 0, Different for 1
1101 0010
^ 1000 1001
0101 1011
2.5 Move left
Move left : High level discard , Low complement 0
2.6 Move right
An unsigned number : To discard in low order , High compensation 0
Signed number : To discard in low order , High compensation 1
3、 Input and output
function : Modules with independent functions
Standard I / O functions :scanf、printf( There are no restrictions on variable types )
Input and output of characters getchar、putchar
Input : Copy data from keyboard to memory
Output : Copy data from memory to the display
3.1 Output
int printf(“ Format control string ”, Output table );
Format control string : Output as is ( It saves ) + Formatter
Output table : Object to output
integer :
%d: Decimal integer
%o: Octal integer
%x、%X: Hexadecimal integer
#: Automatically prefix octal and hexadecimal
%u: An unsigned integer
%hd:short type
%ld:long type
%lld:long long type
character :
%c: Character
floating-point :
%f:float
%lf:double
%e: Index
%g: Choose the shorter of decimal and exponential
.n: Retain n Decimals
m: Specify the domain width of our output , The default is right alignment ,m The value of is greater than the actual length of the data , Fill in the space on the left , otherwise
, Original output
3.2 Input
int scanf(“ Format control string ”, Address table );
Be careful :
- scanf In the format string statement , Don't add modifiers , If you want to add , Input as is
- If input “%d%d” Assign values to multiple variables , There is no interval in the format string , Then when typing on the keyboard , With spaces 、 enter 、Tab The key ends as the input of a variable
- All input ends , Must end with carriage return
- If it is “%c%c“ when , There should be no blank space when inputting 、 enter 、Tab key , Because of the space 、Tab key 、 Carriage return is also a character
terms of settlement :1、%c%c Add a space or comma between ( Input as is )
2、 Add %*c,* Represents the time suppressor
3.3 Input and output of characters
int getchar();
Return value : Characters obtained from the keyboard ASCII code
char a;
a = getchar();
int putchar(int c);
Parameters c: What you want to output ASCII Code value
边栏推荐
- 个人博克系统登录点击图形验证码的集成与实现
- [网络]跨区域网络的通信学习IPv4地址的分类和计算
- The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced
- English translation Arabic - batch English translation Arabic tools free of charge
- Cdga | how can the industrial Internet industry do a good job in data governance?
- How does app automated testing achieve H5 testing
- [network] communication across regional networks learn how routing tables work
- MySQL8 tmp_ table_ Size and Max_ heap_ table_ size
- Thoroughly understand bit operations - shift left, shift right
- Edge detection and connection of image segmentation realized by MATLAB
猜你喜欢

Servlet学习笔记

认识中小型局域网WLAN

The results of the second quarter online moving people selection of "China Internet · moving 2022" were announced

你知道雨的类型有几种?

Intermediate soft test (system integration project management engineer) high frequency test site

High beam software has obtained Alibaba cloud product ecological integration certification, and is working with Alibaba cloud to build new cooperation

2022年下半年系统集成项目管理工程师认证8月20日开班

【NPP安装插件】

Theoretical knowledge of digital image (I) (personal analysis)

“中国网事·感动2022”二季度网络感动人物评选结果揭晓
随机推荐
Intermediate soft test (system integration project management engineer) high frequency test site
Leetcode Day2 consecutive numbers
Stories of Party members | Li qingai uses cartoons to drive farmers to increase income and become rich
shared_ptr 和 make_shared 的使用
Android-第十三节03xUtils-数据库框架(增删改查)详解
Basic concept and essence of Architecture
Information management system and games based on C language
editor.md中markdown编辑器的实现
KPMG China: insights into information technology audit projects of securities fund management institutions
NetCoreAPI操作Excel表格
Edge detection and connection of image segmentation realized by MATLAB
云原生编程挑战赛火热开赛,51 万奖金等你来挑战!
克服“看牙恐惧”,我们用技术改变行业
【经验之谈】关于维修电子设备的几点建议和经验
JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver
With the help of panel industry innovation, will FPGA become the best choice for TCON?
Preliminary learning function (3rd blog)
【NPP安装插件】
Leetcode Day5 delete duplicate email
中国能否在元宇宙的未来发展中取得突破,占领高地?