当前位置:网站首页>Pengge C language sixth class
Pengge C language sixth class
2022-07-26 10:43:00 【ZhuMou】
One . Original code , Inverse code , Complement code
Integer in C Language is stored in binary code . Unsigned integer binary code unsigned bit , Only numeric digits ; The highest bit of binary code with signed integer is the sign bit , The following is numeric digit .0 For integers ,1 It's a negative number . Positive integer complement ( The original code, inverse code and complement of positive integer numbers are the same ) stored , Negative integer numbers are stored in complement .
From the literal value of signed integer to the original code :
The symbol is +, Symbol bit 0;
The symbol is -, Symbol bit 1.
The original code, inverse code and complement of positive integer numbers are the same . The original code of negative integer numbers is in addition to the sign bit , According to the not , Get the inverse ; Counter code plus 1, Get the complement .
Negative integer numbers are stored in memory in the form of complements , This is for the convenience of addition ( Subtraction ) operation . But when translated into literal quantity , The original code is used ( Will translate the complement into the original code ).
Consider the following code :
#include <stdio.h>
int main() {
int a = 0;//00000000 00000000 00000000 00000000
int b = ~a; // This assignment statement means “11111111 11111111 11111111 11111111” yes b In memory form ( Complement code )
printf("%d\n",b);// The result is -1
return 0;
}Two .auto,register,static keyword ,typedef Preliminary usage of keywords
typedef: type ( heavy ) Define the operator .
One of the simplest functions is to redefine types
typedef unsigned int u_int;
unsigned int a = 10;//unsigned int It may be too long
// Equivalent to u_int a = 10;
// Use typedef A common mistake of is to associate it with #define confusion , I didn't add it later ;The problem of the redefined scope of use will not be discussed for the time being .
auto: All local variables default to automatic (automatic) Variable . meaning : Enter the scope and automatically create , Out of scope auto destroy . Such as :auto int a=10; however auto Generally omit . So it seems ,auto Only applicable to local variables , It reflects the relationship between the life cycle of local variables and their scope .
static: There are three situations .
1. Modify local variables
The difference in auto, Changing the life cycle of local variables . Once the local variable is created , Can survive until the end of the program .
2. Modify global variable
Changed the scope of local variables . Is a global variable that can only be used in the source file that defines it . This is very useful for multi file programming when setting variable access permissions between files
3. Modify function
Similar to global variables . Changed the link properties of the function . Can be called by a source file other than the one that defines it , External link properties called functions ; Can only be called by the source file that defines it , Internal link attribute called function .
Functions should also be declared before use , And the function is externally linkable by default . Add... Before it static Cancel its external link attribute , Make it an internal link function .
( From the study here, we can find , The previous understanding of the life cycle of local variables is incorrect : Previously, it was thought that the life cycle of local variables starts from entering its scope , To leave its scope . This is not comprehensive , Not thinking about static The condition of embellishment )
// Source 1.cpp
int sum(int a, int b) {
return a + b;
}
int a = 10;// Source 2.cpp
#include <stdio.h>
int sum(int, int);// Functions and variables must be declared before use
extern int a;
int main() {
printf("%d\n",sum(1,2));
printf("%d\n",a);
return 0;
}
// correct , Can run // if sum and a add static keyword , Running source 2.cpp An unresolved error will occur when
// Source 1.cpp
static int sum(int a, int b) {
return a + b;
}
static int a = 10;3、 ... and .#define Defining macro
#define Previously used to define identifier constants . Now used to define macros . Macros can be used to replace some simple functions .
#include <stdio.h>
#define MAX(X,Y) X>Y?X:Y
int main(){
int max=MAX(1,2);
printf("%d\n",max);
return 0;
}Put it further later
Four . Origin of pointer and address
First, introduce the origin of the address . The operating system is divided into 32 Bit and 64 position . With 32 For example, bit operating system ,32 Bit means 32 Root address line .32 The root address line means there is 2^32 Different addresses . These addresses correspond to the unique memory unit . Each such address unit is 1 byte, thus ,2^32 A memory unit means 4G Of memory .
This is the origin of the address .
Here is the pointer . Pointers are variables used to store addresses . The data type of pointer variable can be :int*, char*, double* wait . The memory occupied by pointer variables depends on the type of operating system ,64 The pointer of the bit system occupies 8bytes,32 The pointer of the bit system occupies 4bytes. Related operators are :& Fetch address ;* Indirect access operators ( Dereference operator )
边栏推荐
- 剑指Offer(四十三):左旋转字符串
- .net operation redis sorted set ordered set
- RT thread learning notes (I) -- configure RT thread development environment
- Flutter 防止科学计数并去除尾数无效0
- Constructors, method overloads, object arrays, and static
- RT-Thread 学习笔记(六)--- 开启基于SPI Flash的elmfat文件系统(上)
- Pengge C language lesson 4 (3)
- el-table实现可编辑表格
- 第7期:内卷和躺平,你怎么选
- 字典与int矩阵
猜你喜欢
![[leetcode daily question 2021/5/8]1723. The shortest time to complete all work](/img/e7/a48bb5b8a86cbc4cd5b37bb16661a8.png)
[leetcode daily question 2021/5/8]1723. The shortest time to complete all work
![[leetcode daily question 2021/4/23]368. Maximum divisible subset](/img/0b/32ca862963c842a93f79eaac94fb98.png)
[leetcode daily question 2021/4/23]368. Maximum divisible subset

242.有效的字母异位词

Issue 5: the second essential skill for College Students

PLC与伺服电机连接

粽子大战 —— 猜猜谁能赢

抽象工厂及其改进示例
![[leetcode daily question 2021/2/18] [detailed explanation] minimum number of turns of 995. K continuous bits](/img/de/62fca587cde95110c2a967ca93eea5.png)
[leetcode daily question 2021/2/18] [detailed explanation] minimum number of turns of 995. K continuous bits

【小程序】onReachBottom 事件为什么不能触发 ?(一秒搞定)
![[leetcode daily question 2021/8/30]528. Choose randomly by weight [medium]](/img/13/c6cb176d7065035f60d55ad20ed1bf.png)
[leetcode daily question 2021/8/30]528. Choose randomly by weight [medium]
随机推荐
Oracle create index
Anaconda is used on vscode (the environment has been configured)
10 let operator= return a reference to *this
display-inline+calc实现左中右布局,中间自适应
剑指Offer(八):跳台阶
putty的使用教程
The problem of large fluctuation of hx711 data
【小程序】onReachBottom 事件为什么不能触发 ?(一秒搞定)
解决:无法加载文件 C:\Users\user\AppData\Roaming\npm\npx.ps1,因为在此系统上禁止运行脚本 。
[leetcode daily question 2021/2/14]765. Lovers hold hands
RT-Thread 学习笔记(八)---开启基于SPI Flash的elmfat文件系统(下)
$router和$route的区别
[dectectron2] follow the official demo
RT thread learning notes (VII) -- open the elmfat file system based on SPI flash (middle)
Sql Server 之SQL语句对基本表及其中的数据的创建和修改
文案秘籍七步曲至----文献团队协作管理
Uninstall Meizu app store
剑指Offer(二十):包含min函数的栈
(转载)ArcGIS Engine中各种点的创建方法
使用flex实现左中右布局,中间自适应