当前位置:网站首页>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’)
边栏推荐
- The best time to buy and sell stocks
- Brain tree (I)
- QT loading third-party library basic operation
- 14 -- validate palindrome string II
- Arithmetic operations and expressions
- Judging the number of leap years from 1 to N years
- JS component
- JGG | 河北大学杜会龙组综述植物泛基因组学研究
- Review of arrays and pointers triggered by a topic
- 15 -- 最接近原点的 K 个点
猜你喜欢

How to cut the size of a moving picture? Try this online photo cropping tool

【Try to Hack】vulnhub DC1

Gif动画怎么在线制作?快试试这款gif在线制作工具

C language escape character and its meaning

Jaspersoft studio installation

Ubuntu 20.04 installing mysql8.0 and modifying the MySQL password

【中国海洋大学】考研初试复试资料分享

Master XSS completely from 0 to 1

【Try to Hack】vulnhub DC1

如何裁剪动图大小?试试这个在线照片裁剪工具
随机推荐
[HBZ sharing] use of locksupport
Using Sphinx to automatically generate API documents from py source files
【深度学习】多任务学习 多个数据集 数据集漏标
[untitled]
多张动图怎样合成一张gif?仅需三步快速生成gif动画图片
2022年广东高考分数线出炉,一个几家欢喜几家愁
Biscuit distribution
Is it normal to dig for money? Is it safe to open a stock account?
Common classes in QT
JS Base64 Library Learning
NBD Network Block Device
Daily question, magic square simulation
【Try to Hack】vulnhub DC1
Uniapp cloud packaging app
basic_ String mind map
QT loading third-party library basic operation
One question per day, a classic simulation question
QT database connection deletion
【中國海洋大學】考研初試複試資料分享
One question per day, punch in