当前位置:网站首页>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 )
边栏推荐
- 12 don't forget every component when copying an object
- 超图 影像 如何去除黑边(两种方法)
- putty的使用教程
- 鹏哥C语言——扫雷2021-08-16
- px2rem-loader将px转化为rem,适配移动端vant-UI等框架
- Problems encountered in QRcode QR code (C language)
- shell 脚本 失败自动重复执行
- C language callback function
- Issue 5: the second essential skill for College Students
- 如何实现临时的图形要素现实
猜你喜欢

20210807#1 C语言程序结构

RT-Thread 学习笔记(六)--- 开启基于SPI Flash的elmfat文件系统(上)

Issue 5: the second essential skill for College Students

Codepoint 58880 not found in font, aborting. flutter build apk时报错

RT thread learning notes (I) -- configure RT thread development environment

RT-Thread 学习笔记(五)---编辑、下载、调试程序

用两个栈实现队列

RT-Thread 学习笔记(三)---用SCons 构建编译环境

Issue 6: which mainstream programming language should college students choose

The problem of formatting IAR sprintf floating point to 0.0 in UCOS assembly
随机推荐
27.移除元素
RT-Thread 学习笔记(三)---用SCons 构建编译环境
多目标优化系列1---NSGA2的非支配排序函数的讲解
剑指Offer(八):跳台阶
Problems encountered in QRcode QR code (C language)
Issue 5: the second essential skill for College Students
flutter 背景变灰效果,如何透明度,灰色蒙板遮罩
第6期:大学生应该选择哪种主流编程语言
7-25 0-1背包 (50分)
文案秘籍七步曲至----文献团队协作管理
flutter dart生成N个区间范围内不重复随机数List
回到顶部的几种方案(js)
json_ object_ put: Assertion `jso->_ ref_ count > 0‘ failed. Aborted (core dumped)
Flutter TextField怎样去除下划线及有焦点时颜色
Dry goods likeshop takeout order system is open source, 100% open source, no encryption
Oracle create index
Issue 7: how do you choose between curling up and lying flat
RT-Thread 学习笔记(一)---配置RT-Thread开发环境
从蚂蚁的觅食过程看团队研发(转载)
RT-Thread 学习笔记(七)---开启基于SPI Flash的elmfat文件系统(中)