当前位置:网站首页>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
边栏推荐
- Germany and Portugal have announced that they will not disable Huawei 5g equipment, but Germany will set strict restrictions!
- Data system of saltstack
- Netcoreapi operation excel table
- Redis笔记
- Cell review: single cell methods in human microbiome research
- leetcode day3 查找重复的电子邮箱
- Leetcode day3 find duplicate email addresses
- Basic concept and essence of Architecture
- 基于C语言的信息管理系统和小游戏
- First blog
猜你喜欢
一文读懂如何部署具有外部数据库的高可用 K3s
How to write the SQL statement of time to date?
毕马威中国:证券基金经营机构信息技术审计项目发现洞察
Servlet learning notes
Deploy ZABBIX automatically with saltstack
How does app automated testing achieve H5 testing
JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver
“中国网事·感动2022”二季度网络感动人物评选结果揭晓
Common APIs in string
2022年全国最新消防设施操作员(中级消防设施操作员)题库及答案
随机推荐
Data system of saltstack
CodeIgnier框架实现restful API接口编程
Leetcode day3 find duplicate email addresses
MySQL8 Status Variables: Internal Temporary Tables and Files
NetCoreAPI操作Excel表格
OpenOCD如何通过stlink直接下载程序到stm32板子(已解决)
Preliminary learning function (3rd blog)
Leetcode day2 连续出现的数字
Prometheus deployment
KPMG China: insights into information technology audit projects of securities fund management institutions
你知道雨的类型有几种?
MySQL8 Status Variables: Internal Temporary Tables and Files
What parameters should be passed in calling integer or character array functions
English translation Arabic - batch English translation Arabic tools free of charge
shared_ PTR and make_ Use of shared
Source code analysis of scripy spider
shared_ptr 和 make_shared 的使用
基于C语言的信息管理系统和小游戏
JS preventdefault() keyboard input limit onmousewheel stoppropagation stop event propagation
My second blog - C language