当前位置:网站首页>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
边栏推荐
猜你喜欢

基于C语言的信息管理系统和小游戏

Cell review: single cell methods in human microbiome research

Saltstack configuration management

English translation Italian - batch English translation Italian tools free of charge

CDGA|工业互联网行业怎么做好数据治理?

How navicate modifies the database name

河北:稳粮扩豆助力粮油生产提质增效

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

adb remount of the / superblock failed: Permission denied

远光软件获得阿里云产品生态集成认证,携手阿里云共建新合作
随机推荐
Idea properties file display \u solution of not displaying Chinese
Leetcode day3 employees who exceed the manager's income
English Translation Spanish - batch English Translation Spanish tools free of charge
leetcode day4 部门工资最高的员工
Basic usage of docker
Leetcode day3 find duplicate email addresses
MySQL 8 creates master-slave replication based on Clone
Taking the opportunity of digital transformation, how can 3C enterprises achieve efficient collaboration through SRM supplier cloud collaboration platform?
通信网络基础知识01
[network] communication across regional networks learn how routing tables work
Left alignment function of Lua language (handwriting)
Source insight project import and use tutorial
Investment of 3.545 billion yuan! Gree Group participates in Xiaomi industry fund
MySQL8 Encrypting InnoDB Tablespaces
远光软件获得阿里云产品生态集成认证,携手阿里云共建新合作
My second blog - C language
Getting started with saltstack
leetcode day1 分数排名
开盘暴涨215%!国产信号链芯片企业芯海科技登陆科创板
云计算笔记part.1——系统管理