当前位置:网站首页>The foundation of writing notes in C language is not solid, and the earth is shaking
The foundation of writing notes in C language is not solid, and the earth is shaking
2022-07-22 08:42:00 【Populus euphratica under the desert】
Personal home page : Welcome to ——> Populus euphratica under the desert
Ladies and gentlemen , It's beautiful
If you think the article is helpful to you
You can support bloggers with one key and three links
Your every care is the driving force of my persistence
![]()
: This issue focuses on : some C Summary of mistakes prone points of language brush questions
I hope everyone can study and work happily every day .
Four . "A" and 'A' The difference between
5、 ... and . About data storage
6、 ... and . About two-dimensional arrays
7、 ... and . Operator priority
One . About global variables
Can't you use global variables before they are defined ?
extern int a; int main() { printf("a = %d\n", a); return 0; } int a = 10;
Let's see , First int a The definition of is in main After the function , Can be used by declaration .
The essence : First, global variables have been allocated memory space when the program is running , So it can be used before definition .
Two . About scanf
Add the appropriate input statement at the horizontal line , Enter... From the keyboard while the program is running :How are you?< enter >, The final output is : How are you?How
int main() { char *a = "How are you?", b[20]; —————————————————————————————— printf("%s %s\n", a, b); return 0; }
A:gets(b) B:scanf("%s",b)
gets The end of is line feed ( '\n' )
scanf The end is a space enter Tab key , That is, a continuous character .
So we should choose B:scanf("%s",b)
3、 ... and . Pointer practice
int a[10] = { 1, 2, 3, 5, 5, 6, 7, 8, 9, 10 }; int x = 0; int *pa = a;
With the above definition , Then in the following assignment , Which one doesn't subscript the array to 3 The element of is assigned to x Well ?
A:x = pa[3] B:x= *(a+3)
C: x =a[3] D:x = *pa+3
Under the analysis of :
A: correct ,pa Although it's a pointer , But it can be accessed in the form of an array .
B: correct ,a It's the first element address , Move successively 3 individual int Size , Just access to the subscript 3 The elements of , Assignment in dereference
C: correct , In the form of an array , Mark the subscript as 3 The value of is assigned to x 了 .
D: error , The first is to directly dereference a Is the first element of the array , And then in +3, This is not true .
Four . "A" and 'A' The difference between
First character 'A' Is a single character , and "A" It's two characters ,A and \0, They are different .
5、 ... and . About data storage
Look directly at the code :
unsigned short A = 10; printf("~A = %u\n", ~A); char c = 128; printf("c = %d\n", c);
Let's analyze it A:
Deposit in A In space is 00000000 00001010 , Then on A Carry out bit inversion to become 11111111 11110101
And then according to %u Print , Is to shape and print according to the unsigned, that is 11111111 11111111 11111111 11110101
The result of printing is 4294967285
Then analyze c :
c yes 128, The storage space is 10000000, yes %d Print , So plastic surgery is promoted to
11111111 11111111 11111111 10000000, This is the complement ,
Convert to inverse code 10000000 000000000 00000000 01111111
The original code is 10000000 000000000 00000000 10000000,
The final print is -128
6、 ... and . About two-dimensional arrays
The following output results :
char arr[2][4]; strcpy(arr[0], "you"); strcpy(arr[1], "me"); arr[0][3] = '&'; printf("%s \n", arr);
Let's analyze first :
The data put after the first copy is ,
The data put after the second copy is ,
At this time, if we directly take %s If you print it , Then it will print to '\0' end , But we did the assignment operation , hold arr[0][3] in '\0', Replace with ' $ ', So the result is " you&me ".
7、 ... and . Operator priority
*p++ Is a self increasing pointer p Or self increasing pointer p What it points to ?
Look at a code :
int a = 10; int *p = NULL; int **pp = NULL; p = &a; pp = &p; printf("%d\n", *pp); printf("%d\n", *p++); printf("%d\n", *pp);
When we run it directly, we can get , Is self increasing, is a pointer variable p.
There are two schools of explanation :1. stay C And pointer are interpreted as , Under the same priority , The combination is from right to left .
2. On the priority diagram , For post ++ Has priority over dereference ( * ).
Let's discuss this in the discussion area !
边栏推荐
- P[0] as the judgment condition of the for loop
- Soft exam intermediate [Database System Engineer] Chapter 1: computer system knowledge, self-study soft exam notes, preparation for the soft exam in May 2022, computer hardware system CPU composition
- 解释内存中的栈(stack)、堆(heap)和方法区(method area)的用法
- Quantitative transaction journal - fallback analysis - February 6, 2021
- 自学golang【3.5go语言数组,range关键字】数组的定义方式,使用for循环遍历一维数组
- 量化交易中如何判断趋势
- How to add text before and after text in batch in Excel
- MySQL中MyISAM和InnoDB的区别与实现
- The use of comma expression in C language
- 七/四/五层网络模型
猜你喜欢
硬件看门狗的实现
RPA是什么?推荐让电商运营10倍提效的自动化工具
Verilog -- 74hc194 multifunctional bidirectional shift register
Verilog application - 24 second basketball counter
软考中级【数据库系统工程师】第2章:程序语言基础知识,自学软考笔记,程序语言概述程序语言翻译基础低级语言和高级语言编译和解释的区别中缀、前缀与后缀表达式程序语言的数据成分1)常量和变量2)全局变量和局
How does pytorch convert a variable or tensor to numpy?
七/四/五层网络模型
Self study golang [Chapter 1: basic knowledge of go language] Why do you want to learn go language? The relationship between go language and C language? Founder of go language? What are the characteri
C语言刷题笔记之基础不牢地动山摇 <一>
量化交易中通过均线系统判断上涨(下跌)动能减弱
随机推荐
编码之前先保证你的硬件稳定连接!!!
MySQL stored procedure
TPS trading strategy with a winning rate of 93.98%
MySQL事务
Self study golang [3.3go language loop statement] for loop syntax structure, omit initial conditions, omit incremental conditions, omit the application of end conditions
Shell exercise: Statistics of word frequency
一个交易系统需要经过几年的考验才算成功的交易系统,盈利需要几年才算稳定?
自学golang【3.6切片slice的练习代码】切片的长度,上限,复制,删除与增加
MySQL存储过程
youtube字幕下载
房屋排序法
[quick start of flex layout] quickly understand the usage of flex layout, and explain it through four common layout cases [detailed notes, as soon as you see it]
Zhang Chi Consulting: the fifth Six Sigma project of a packaging and printing group passed the expert review
在 EXCEL 中,“插入已剪切单元格”的快捷键
SPI调试不成功很有可能是你线接错了!!
“珠峰”架构强势赋能 第三代荣威RX5/超混eRX5刷新产品力“天花板”
Partage de la stratégie de percée ultime des commerçants professionnels pendant de nombreuses années (avec un ensemble complet de modèles de transaction)
自学golang【3.8使用go语言实现寻找最长不含有重复字符的子串】练习代码
Continuously improve cognition, so as to reach the highest level of trading - stable profits (I)
Error: L6200E: Symbol keyflag multiply defined (by main.o and key.o).