当前位置:网站首页>Learning notes on February 8, 2022 (C language)
Learning notes on February 8, 2022 (C language)
2022-06-25 14:55:00 【Smart_ auspicious】
22/2/8 Learning notes (Part 2)
notes
Comments are used to explain complex code .
//int a = 10;
//C++ Annotation style
/* int b = 10; */
//C Language annotation style - Nested comments are not supported
Array
An array is a collection of elements of the same type .
- int arr —— Array of numbers
int arr[10] = {
1,2,3,4,5,6,7,8,9,10};
- char ch—— A character array
char ch[5] = {
‘a’,’b‘,’c‘}; // Incomplete initialization , The rest of the following defaults to 0
Escape character
Escape character ( Changed the original meaning )
| Escape character | paraphrase |
|---|---|
| \ ? | Use... When writing multiple consecutive question marks , Prevent them from being parsed into three letter words |
| \ ’ | Used to represent character constants ‘ |
| \ " | Double quotation marks used to represent the inside of a string |
| \ \ | Used to indicate a backslash , Prevent it from being interpreted as an escape sequence character |
| \ a | Warning characters , Beep |
| \ b | Back space |
| \ f | Paper in |
| \ n | Line break |
| \ r | enter |
| \ t | Horizontal tabs |
| \ v | Vertical tabs |
| \ ddd | ddd Express 1~3 Eight octal numbers . Such as :\130X |
| \ xdd | dd Express 2 Hexadecimal numbers . Such as : \x30 0 |
Three letter words such as "??) It will be interpreted as ]
Simple operators
| type | Specifically |
|---|---|
| Arithmetic operators | + - * / % |
| Shift operator | >> << |
| Bit operators | &( Bitwise AND ) 、 ^( Press bit or ) 、 l( Bitwise XOR ) |
| Assignment operator | =、+=、-=、*=、/=、&=、^=、l=、>>=、<<= |
| Monocular operators | 【 See the table below 】 |
| Relational operator | >、>=、<、<=、!=( The tests are not equal )、==( Test equality ) |
| Logical operators | &&( Logic and )、ll( Logic or ) |
| Conditional operators | exp( expression )1?exp2:exp3 |
| Comma expression | exp1,exp2,exp3,…,expN |
| Other operators | [] Subscript reference 、() Function call 、. Structural members 、-> Structural members |
| Monocular operators | paraphrase |
|---|---|
| ! | Logical anti operation |
| - | negative |
| + | Comes at a time |
| & | Address fetch |
| sizeof | The type length of the operands ( In two bytes ) |
| ~ | To reverse the binary of a number |
| - - | In front of - -、 After - - |
| ++ | In front of ++、 After ++ |
| * | Indirect access operators ( Dereference operator ) |
| ( type ) | Cast |
1、 The arithmetic operation needs to be programmed according to the floating-point precision :
float a = 9 / 2.0; // First float The premise for decimal calculation , Secondly, when both sides of the division sign are integers, the result is an integer , When a floating-point precision bit appears , The result will float to this bit .
printf("%f\n",a);
2、% The meaning of the arithmetic operator of is “ modulus ”, namely “ Remainder ”.
int a = 9 % 2;
printf("%d\n",a); // The result displayed on the screen is 1
3、+= This kind of meaning is :
a=10;
a = a + 1;
// Can be written a += 1
a = a % 3;
// Can be written a %= 3
4、a + b here + It's a binocular operator , Empathy , Unary operator means that there is only one operand .
5、 The size of an element is 4 byte .
int arr[10] = {
0};
printf("%d\n",sizeof(arr)); // The total size of the array is calculated , Unit is byte , The result is 40 //10( Elements )*4( Unit byte )=40
printf("%d\n",sizeof(arr[0])) // The result is 4
6、~ Bitwise negation means that all the digits in the binary bits are 1 become 0,0 become 1.
int main()
{
int a = 0;
printf("%d\n",~a);
return 0;
} // The output is -1
// 0 The binary of is :00000000000000000000000000000000
//~0 The binary of is :1111111111111111111111111111111111111
7、++ Usage of
int main()
{
int a = 10;
int b = ++a; // In front of ++, First ++, After use
printf(“%d\n”,b); // The result is 11
printf("%d\n",a); // The result is 11
return 0;
}
int main()
{
int a = 10;
int b = a++; // After ++, First use , after ++
printf(“%d\n”,b); // The result is 10
printf("%d\n",a); // The result is 11
return 0;
}
8、 Cast
int main()
{
int a = (int) 3.14; // This is a different type , Use (int) Coercive transformation
printf("%d\n",a);
return 0;
}
9、 The conditional operator is also called the trinocular operator
exp1?exp2:exp3
exp1 establish ,exp2 Calculation , The result of the entire expression is exp2 Result .
exp1 Don't set up ,exp3 Calculation , The result of the entire expression is exp3 Result .
10、 Comma expressions are evaluated from left to right , The result of the entire expression is the result of the last expression .
Little tips
Why? VC6.0 When a written program cannot run , Show this file does not exist ?
One 、 open VC6.0 after , When creating a new file , You need to pay attention to the files you create No “C Header File” Format , It is “C source File” Format .
Two 、 Add a file name to your file and the location where the file is stored , At this point, you can see that it is “c or cpp” For the suffix The suffix file of , and Not in “txt or h” For the suffix The suffix file of .
3、 ... and 、 Ensure that the code format is correct .
Four 、 When you run the program , If prompted “ Unable to execute program ”, Press CTRL Add F7 Composite key , Build , Press the shortcut key again CTRL Add F5 Composite key , Finally according to the Y, That is, the program can be executed successfully .The binary representation of an integer has 3 Kind of : Original code 、 Inverse code 、 Complement code .
Integers are stored in memory as complements .
The way negative numbers are calculated ( Original code of positive integer 、 Inverse code 、 The complement is the same ):-1 For example :
10000000000000000000000000001( Original code )
11111111111111111111111111110( Inverse code )
11111111111111111111111111111( Inverse code +1 For the complement )printf When printing data , Format can be specified .
printf("%d",100);
printf("%c",'a');
printf("%s","abc");
- ASCII surface ( Character base conversion )
- int Table ID ;sacnf Table input

When the above figure is converted to function ( Function as called module , Very important in complex code ) When expressing :
#include<stdio.h>;
Add(int x,int y)
{
int z = 0;
z = x + y;
return z;
} // And the function
int main()
{
int num1 = 0; // Identification number 1
int num2 = 0; // Identification number 2
scanf("%d%d", &num1, &num2); // Input Numbers 1 Numbers 2
int sum = Add(num1,num2); // Identify usage and functions
printf("%d\n",sum); // Print out and
return 0;
}
subject
What does the following program output ?
#include<stdio.h>;
int main()
{
printf("%d\n",strlen("abcdef"));
// \32 Parsed into an escape character
printf(“%d\n”,strlen("c:\text\328\text.c"));
return 0;
}
answer
Output :
6(“abcdef” It's six , All lengths are 6)
14( Escape character , Having a length 14 The bit characters are :‘c’、’:’、’\t’、‘e’、‘x’、‘t’、’\32’、‘8’、’\t’、‘e’、‘x’、‘t’、’.’、‘c’)
边栏推荐
- Time stamp calculation and audio-visual synchronization of TS stream combined video by ffmpeg protocol concat
- Iterator failure condition
- Native JS obtains form data and highlights and beautifies JSON output display
- QT database connection
- Let and const commands
- Is it normal to dig for money? Is it safe to open a stock account?
- 买基金在哪里开户安全?求指导
- [HBZ sharing] use of locksupport
- Use Matplotlib to draw a line chart
- 【Try to Hack】vulhub靶场搭建
猜你喜欢

Review of arrays and pointers triggered by a topic

JGG | overview of duhuilong group of Hebei University Research on plant pan genomics

Using Sphinx to automatically generate API documents from py source files

电源自动测试系统NSAT-8000,精准高速可靠的电源测试设备

basic_ String mind map

Std:: vector minutes

Source code analysis of synergetics and ntyco

SPARQL learning notes of query, an rrdf query language

JGG | 河北大学杜会龙组综述植物泛基因组学研究

Application of TSDB in civil aircraft industry
随机推荐
Luogu p5707 [deep foundation 2. example 12] late for school
Judging the number of leap years from 1 to N years
dev/mapper的解释
Uniapp icon configuration
Build a minimalist gb28181 gatekeeper and gateway server, establish AI reasoning and 3D service scenarios, and then open source code (I)
QT opens the print dialog box in a text editor
Go语言Zap库Logger的定制化和封装使用详解
【Try to Hack】vulnhub DC1
Heavyweight! The domestic IDE is released and developed by Alibaba. It is completely open source! (high performance + high customization)
One question per day, punch in
分饼干问题
JS to add elements to the header, or tail of an array
JS floating point multiplication and division method can not accurately calculate the problem
Ideal L9 in the eyes of the post-90s: the simplest product philosophy, creating the most popular products
Common classes in QT
Character encoding minutes
Study notes of cmake
Daily question, Caesar code,
What is the safest app for stock account opening? Tell me what you know
Is it normal to dig for money? Is it safe to open a stock account?