-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.xml
3142 lines (2941 loc) · 332 KB
/
search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>C++面向对象的三大特性</title>
<url>/posts/ac27/</url>
<content><![CDATA[]]></content>
<categories>
<category>C++</category>
</categories>
<tags>
<tag>C++</tag>
<tag>面向对象</tag>
</tags>
</entry>
<entry>
<title>Github下载加速</title>
<url>/posts/79ca/</url>
<content><![CDATA[<p><strong>准备条件</strong></p>
<ul>
<li>码云(Gitee账号)</li>
</ul>
<p>注册地址:<a href="https://gitee.com/" target="_blank" rel="noopener">https://gitee.com/</a></p>
<ul>
<li>Git</li>
</ul>
<p>镜像下载地址:<a href="https://npm.taobao.org/mirrors/git-for-windows" target="_blank" rel="noopener">https://npm.taobao.org/mirrors/git-for-windows</a></p>
<h2 id="1-码云-Gitee-导入"><a href="#1-码云-Gitee-导入" class="headerlink" title="1.码云(Gitee)导入"></a>1.码云(Gitee)导入</h2><p>1.以<code>Github</code>上Stars较多的一个优秀的Java学习路线项目为例</p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/30/6e61b1ed8495188950dfd0b73705b957.png" alt="image-20200630113350201"></p>
<blockquote>
<p>1.复制项目的网址</p>
</blockquote>
<p><a href="https://github.com/Snailclimb/JavaGuide" target="_blank" rel="noopener">https://github.com/Snailclimb/JavaGuide</a></p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/30/b5928fa75fe216915bfa5f0611796b28.png" alt="image-20200630113456261"></p>
<blockquote>
<p>2.导入项目到Gitee</p>
</blockquote>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/30/d2e4a08b94327d6b0ce9569607ee63f2.png" alt="image-20200630113727080"></p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/30/1202564fd464d7efa445f44a5679d0a8.png" alt="image-20200630114432345"></p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/30/4d52e8150d9f81182e386a8882d4d70f.png" alt="image-20200630114647419"></p>
<p><strong>导入后等待页面加载即可</strong></p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/30/88d8e95cbbe78cb93e8c43f00cf92f57.png" alt="image-20200630114914779"></p>
<p><strong>将项目克隆到本地</strong></p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/30/ecd4d35e1eac4e6a71efe1089f855fbd.png" alt="image-20200630115427594"></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment">#git clone 码云上的项目地址</span></span><br><span class="line">git <span class="built_in">clone</span> https://gitee.com/crow_678/JavaGuide.git</span><br></pre></td></tr></table></figure>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/30/10b6c23c7bbcfddebbd608468a2754ff.png" alt="image-20200630115535023"></p>
<p><strong>速度还行</strong></p>
<p><strong>当我们导入一个比较大的项目时</strong></p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/30/71747e5f946516ec19148fcfd9003832.png" alt="image-20200630120819524"></p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/30/e702ecef3ef4897a5a88f509587c1494.png" alt="image-20200630121226310"></p>
<h2 id="2-使用在线的网站"><a href="#2-使用在线的网站" class="headerlink" title="2.使用在线的网站"></a>2.使用在线的网站</h2><p><a href="http://g.widyun.com/" target="_blank" rel="noopener">http://g.widyun.com/</a></p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/30/7aa20b8396ecd033331e7199c956bd3f.png" alt="image-20200630121331482"></p>
<p><strong>复制项目网址到中间的输入框,点击获取连接耐心等待</strong></p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/30/b7cdf7a2b2fb2ccbb03901b77a6352ce.png" alt="image-20200630122021103"></p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/30/62fcf183c409d8fb19fae2201204522a.png" alt="image-20200630122104574"></p>
<h2 id="1-仓库名称"><a href="#1-仓库名称" class="headerlink" title="1.仓库名称"></a>1.仓库名称</h2><ul>
<li>springboot stars大于3000的项目并且fork>4000<blockquote>
<p>in:name springboot stars:>3000 forks:>4000<br>in:name 项目名称 stars:数量 forks:数量</p>
</blockquote>
</li>
</ul>
<h2 id="2-Readme-md文件"><a href="#2-Readme-md文件" class="headerlink" title="2.Readme.md文件"></a>2.Readme.md文件</h2><ul>
<li>springboot stars大于3000的项目并且fork>4000<blockquote>
<p>in:readme spring boot stars:>3000 forks:>4000<br>in:readme 项目名称 stars:数量 forks:数量</p>
</blockquote>
</li>
</ul>
<h2 id="3-描述文件"><a href="#3-描述文件" class="headerlink" title="3.描述文件"></a>3.描述文件</h2><ul>
<li>微服务项目 stars>1000 语言为java 最后一次更新时间再2019-09-01之后<blockquote>
<p>in:description 微服务 stars:>1000 language:java pushed:>2019-09-01<br>in:description 项目名称 stars:数量 forks:数量 language:编程语言 pushed:更新时间</p>
</blockquote>
</li>
</ul>
<p>in:description 项目名称 stars:数量 forks:数量 language:编程语言 pushed:更新时间</p>
<p><strong>Github官方使用文档</strong><br><a href="https://help.github.com/en/github/searching-for-information-on-github/searching-for-repositories" target="_blank" rel="noopener">https://help.github.com/en/github/searching-for-information-on-github/searching-for-repositories</a></p>
]]></content>
<categories>
<category>生产力</category>
</categories>
<tags>
<tag>Github</tag>
</tags>
</entry>
<entry>
<title>C语言程序设计概述</title>
<url>/posts/c5a3/</url>
<content><![CDATA[<h1 id="C语言程序设计概述"><a href="#C语言程序设计概述" class="headerlink" title="C语言程序设计概述"></a>C语言程序设计概述</h1><h2 id="1-C语言的发展历程"><a href="#1-C语言的发展历程" class="headerlink" title="1.C语言的发展历程"></a>1.C语言的发展历程</h2><ul>
<li>1.为什么发明C语言:C语言的诞生是和UNIX操作系统的开发密不可分的,原先的UNⅨX操作系统都是用汇编语言写的,1973年UNIX操作系统的核心用C语言改写,从此以后,C语言成为编写操作系统的主要语言</li>
<li>2.C语言对其它语言的影响:很多编程语言都深受C语言的影响,比如C艹(原先是C语言的一个扩展)、C#、 Java、PHP、 Javascript、Perl、LPC和UNIX的 C Shell等</li>
<li>掌握C语言的人,再学其它编程语言,大多能很快上手,触类旁通,很多大学将C语言作为计算机教学的入门</li>
<li>C语言之父 <strong>丹尼斯·麦卡利斯泰尔·里奇</strong>(英语:<strong>Dennis MacAlistair Ritchie</strong></li>
</ul>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn/img/20200703203727.png" alt="1-15030119511M02"></p>
<p><strong>程序:</strong></p>
<ul>
<li>为了<code>计算机</code><strong>执行某些操作或解决某个问题</strong>而编写的一系列<strong>有序指令的集合</strong></li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="comment">//引入头文件</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><stdio h></span></span></span><br><span class="line"><span class="comment">//main函数,是程序的执行入口,即程序是从main函数开始执行</span></span><br><span class="line"><span class="comment">//void表示main函数没有返回值</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">()</span> </span>{</span><br><span class="line"> <span class="comment">//函数体</span></span><br><span class="line"> <span class="comment">//printf是一个函数,需要是一个头文件才能使用</span></span><br><span class="line"> <span class="comment">//printf是在< stdio. h>,需要引入该头文件</span></span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"hello, world!"</span>);</span><br><span class="line"> <span class="comment">//让窗口停留</span></span><br><span class="line"> getchar;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h2 id="2-C语言的特点"><a href="#2-C语言的特点" class="headerlink" title="2.C语言的特点"></a>2.C语言的特点</h2><ul>
<li>代码级别的<strong>跨平台</strong>:由于标准的存在,使得几乎同样的C代码可用于多种操作系统,如 Windows、DOS、UNIX等等;也适用于多种机型。</li>
<li><strong>允许直接访问物理地址</strong>,<strong>对硬件进行操作</strong> 因此它<strong>既具有高级语言的功能</strong>,<strong>又具有低级语言的许多功能</strong>,C语言可用来写系统软件(比如操作系统,数据库,杀毒软件,防火墙,驱动,服务器程序)。</li>
<li>C语言是一个有<strong>结构化程序设计</strong>、具有<strong>变量作用域( variable scope)</strong>以及<strong>递归功能</strong>的过程式语言</li>
<li>C语言<code>传递参数</code>可以是<code>值传递</code>( pass by value,值),也可以<code>传递指针</code>( a pointer passed by value,地址)也叫<code>引用传递</code></li>
<li>C语言中,没有对象,不同的变量类型可以用结构体( struct)组合在一起</li>
<li>预编译处理( preprocessor),生成目标代码质量高,程序执行效率高</li>
</ul>
<h2 id="3-C语言运行机制"><a href="#3-C语言运行机制" class="headerlink" title="3.C语言运行机制"></a>3.C语言运行机制</h2><p><strong>C程序运行机制过程</strong></p>
<ul>
<li><p>1.编辑:比如编写我们的 hello. c文件,就是<code>源代码</code>,</p>
</li>
<li><p>2.编译:将 <code>hello.c</code>程序通过编译器将其编译成<code>目标文件(hell.obj)</code>在<strong>计算机底层</strong>执行</p>
</li>
<li><p>3.链接:将目标文件 hello. obj + <code>库文件</code>生成可执行文件(My ProjectoR.exe)<strong>计算机底层</strong>执行</p>
<p>链接库文件的原因:我们的C程序中会使用<code>C程序库</code>的内容,比如< stdio.h>< stdlib. h>中的函数printf system()等等,这些函数不是程序员自己写的,而是C程序库中提供的,</p>
<p>链接链接后,生成的exe文件,会比obj文件更大</p>
</li>
<li><p>4.运行:执行<code>exe</code>文件,得到运行结果</p>
<p> <strong>运行机制图解</strong></p>
</li>
</ul>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn/img/20200704093956.png" alt="image-20200704093722914"></p>
<h2 id="4-转义字符"><a href="#4-转义字符" class="headerlink" title="4.转义字符"></a>4.转义字符</h2><table>
<thead>
<tr>
<th>转义字符</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td>\t</td>
<td>一个制表符,用于格式对齐</td>
</tr>
<tr>
<td>\n</td>
<td>换行符</td>
</tr>
<tr>
<td>\\</td>
<td>表示一个\反斜杠</td>
</tr>
<tr>
<td>\“</td>
<td>表示一个”</td>
</tr>
<tr>
<td>\‘</td>
<td>表示一个’</td>
</tr>
<tr>
<td>\r</td>
<td>表示回车</td>
</tr>
</tbody></table>
<h2 id="参考链接"><a href="#参考链接" class="headerlink" title="参考链接"></a>参考链接</h2><div class="btn-center">
<a class="btn-beautify button--animated outline green larger" href="https://www.bilibili.com/video/BV1qJ411z7Hf?p=4" target="_blank" rel="noopener" title="尚硅谷C语言入门"><i class="far fa-hand-point-right fa-fw"></i> 尚硅谷C语言入门 </a>
<a class="btn-beautify button--animated outline green larger" href="https://www.runoob.com/cprogramming/c-standard-library.html" target="_blank" rel="noopener" title="C语言标准库参考手册"><i class="far fa-hand-point-right fa-fw"></i> C语言标准库参考手册 </a>
</div>]]></content>
<categories>
<category>C</category>
</categories>
<tags>
<tag>C</tag>
</tags>
</entry>
<entry>
<title>IDEA快捷键</title>
<url>/posts/aa80/</url>
<content><![CDATA[<h2 id="断点调试"><a href="#断点调试" class="headerlink" title="断点调试"></a>断点调试</h2><p><a href="https://www.cnblogs.com/xiemingjun/p/9618427.html" target="_blank" rel="noopener">https://www.cnblogs.com/xiemingjun/p/9618427.html</a></p>
]]></content>
<categories>
<category>生产力</category>
</categories>
<tags>
<tag>IDEA</tag>
</tags>
</entry>
<entry>
<title>Java面向对象的三大特性</title>
<url>/posts/9d0/</url>
<content><![CDATA[<h2 id="封装"><a href="#封装" class="headerlink" title="封装"></a>封装</h2><ul>
<li>参考链接</li>
<li><a href="https://www.cnblogs.com/chenssy/p/3351835.html" target="_blank" rel="noopener">https://www.cnblogs.com/chenssy/p/3351835.html</a></li>
</ul>
<h2 id="继承"><a href="#继承" class="headerlink" title="继承"></a>继承</h2><ul>
<li>参考链接</li>
<li><a href="https://www.cnblogs.com/chenssy/p/3354884.html" target="_blank" rel="noopener">https://www.cnblogs.com/chenssy/p/3354884.html</a></li>
</ul>
<p>##多态</p>
<ul>
<li>参考链接</li>
<li><a href="https://www.cnblogs.com/chenssy/p/3372798.html" target="_blank" rel="noopener">https://www.cnblogs.com/chenssy/p/3372798.html</a></li>
</ul>
]]></content>
<categories>
<category>Java</category>
</categories>
<tags>
<tag>面向对象</tag>
<tag>Java</tag>
</tags>
</entry>
<entry>
<title>C语言易错点</title>
<url>/posts/9db8/</url>
<content><![CDATA[<h2 id="语法基础"><a href="#语法基础" class="headerlink" title="语法基础"></a>语法基础</h2><ul>
<li><p><strong>getchar()函数</strong>从终端读取一个字符(一次只读取一个字符)并将其作为整数返回</p>
</li>
<li><p><strong>所有C语句必须以分号结尾。</strong></p>
</li>
</ul>
<p><strong>C语言关键字</strong></p>
<table>
<thead>
<tr>
<th>关键字</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>auto</td>
<td>声明自动变量</td>
</tr>
<tr>
<td>short</td>
<td>声明短整型变量或函数</td>
</tr>
<tr>
<td>int</td>
<td>声明整型变量或函数</td>
</tr>
<tr>
<td>long</td>
<td>声明长整型变量或函数</td>
</tr>
<tr>
<td>float</td>
<td>声明浮点型变量或函数</td>
</tr>
<tr>
<td>double</td>
<td>声明双精度变量或函数</td>
</tr>
<tr>
<td>char</td>
<td>声明字符型变量或函数</td>
</tr>
<tr>
<td>struct</td>
<td>声明结构体变量或函数</td>
</tr>
<tr>
<td><strong>union</strong></td>
<td><strong>声明共用数据类型</strong></td>
</tr>
<tr>
<td>enum</td>
<td>声明枚举类型</td>
</tr>
<tr>
<td><strong>typedef</strong></td>
<td><strong>用以给数据类型取别名</strong></td>
</tr>
<tr>
<td>const</td>
<td>声明只读变量</td>
</tr>
<tr>
<td>unsigned</td>
<td>声明无符号类型变量或函数</td>
</tr>
<tr>
<td>signed</td>
<td>声明有符号类型变量或函数</td>
</tr>
<tr>
<td>extern</td>
<td>声明变量是在其他文件正声明</td>
</tr>
<tr>
<td><strong>register</strong></td>
<td><strong>声明寄存器变量</strong></td>
</tr>
<tr>
<td>static</td>
<td>声明静态变量</td>
</tr>
<tr>
<td>volatile</td>
<td>说明变量在程序执行中可被隐含地改变</td>
</tr>
<tr>
<td>void</td>
<td>声明函数无返回值或无参数,声明无类型指针</td>
</tr>
<tr>
<td>if</td>
<td>条件语句</td>
</tr>
<tr>
<td>else</td>
<td>条件语句否定分支(与 if 连用)</td>
</tr>
<tr>
<td>switch</td>
<td>用于开关语句</td>
</tr>
<tr>
<td>case</td>
<td>开关语句分支</td>
</tr>
<tr>
<td>for</td>
<td>一种循环语句</td>
</tr>
<tr>
<td>do</td>
<td>循环语句的循环体</td>
</tr>
<tr>
<td>while</td>
<td>循环语句的循环条件</td>
</tr>
<tr>
<td>goto</td>
<td>无条件跳转语句</td>
</tr>
<tr>
<td>continue</td>
<td>结束当前循环,开始下一轮循环</td>
</tr>
<tr>
<td>break</td>
<td>跳出当前循环</td>
</tr>
<tr>
<td>default</td>
<td>开关语句中的“其他”分支</td>
</tr>
<tr>
<td>sizeof</td>
<td>计算数据类型长度</td>
</tr>
<tr>
<td>return</td>
<td>子程序返回语句(可以带参数,也可不带参数)循环条件</td>
</tr>
</tbody></table>
<ul>
<li><p><strong>实型数据也称为浮点数或实数</strong></p>
</li>
<li><p><code>int</code>C语言中数据类型的合法值范围是-32768-32767</p>
</li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line">main()</span><br><span class="line">{</span><br><span class="line"> <span class="keyword">int</span> i = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">int</span> j = <span class="number">2</span>;</span><br><span class="line"> <span class="keyword">switch</span>(i)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">case</span> <span class="number">1</span>: <span class="built_in">printf</span>(<span class="string">"one"</span>);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> j: <span class="built_in">printf</span>(<span class="string">"two"</span>);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> } </span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p><strong>错误,常量表达式需要代替j。将j改为2</strong></p>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="built_in">printf</span>(<span class="number">5</span> + <span class="string">"Good Morning"</span>);</span><br><span class="line"><span class="comment">//Good Morning</span></span><br></pre></td></tr></table></figure>
<p><strong>跳过后面的字符串的5个字符,然后打印字符串。</strong></p>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line">main()</span><br><span class="line">{</span><br><span class="line"> <span class="keyword">int</span> a =<span class="number">10</span>;</span><br><span class="line"> <span class="keyword">if</span>(a = <span class="number">5</span>)</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"hello"</span>);</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"bye"</span>);</span><br><span class="line">}</span><br><span class="line"><span class="comment">//a=5 赋值操作 输出hello</span></span><br></pre></td></tr></table></figure>
<p><strong>union的大小由最大的成员的大小决定;</strong></p>
<h2 id="指针"><a href="#指针" class="headerlink" title="指针"></a>指针</h2><p><strong>如果变量是指向结构的指针,那么以下哪个运算符用于通过指针变量访问结构的数据成员?</strong></p>
<p><code>-></code></p>
<p><strong>用于访问变量值的运算符在指针变量中存储的地址是?</strong></p>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="keyword">int</span> num = <span class="number">100</span>;</span><br><span class="line"> <span class="keyword">int</span>* ptr = &num;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"ptr本身的地址=%p ptr存放的地址=%p ptr指向的值"</span>,&ptr,ptr,*ptr);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h2 id="结构体"><a href="#结构体" class="headerlink" title="结构体"></a>结构体</h2><p><strong>结构体初始化问题</strong></p>
<p><strong>通过结构体指针访问结构体的变量</strong></p>
<p>1.当结构体内使用字符型的指针<code>char*</code>时</p>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">std</span></span></span><br><span class="line"><span class="class"> {</span></span><br><span class="line"> <span class="keyword">int</span> age;</span><br><span class="line"> <span class="keyword">char</span> *name;</span><br><span class="line"> };</span><br></pre></td></tr></table></figure>
<ul>
<li>结构体初始化</li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">std</span> <span class="title">str</span> = {</span><span class="number">1</span>,<span class="string">"test1"</span>};</span><br></pre></td></tr></table></figure>
<ul>
<li>创建结构体指针</li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">std</span> *<span class="title">s</span> = <span class="title">NULL</span>;</span></span><br></pre></td></tr></table></figure>
<ul>
<li>让指针指向结构体</li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line">s = &str;</span><br></pre></td></tr></table></figure>
<ul>
<li>通过结构体指针访问结构体的成员变量</li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="built_in">printf</span>(<span class="string">"name:%s\n"</span>,(*s).name);</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"age:%d\n"</span>,(*s).age);</span><br></pre></td></tr></table></figure>
<p>2.当结构体内使用字符型数组<code>char[]</code>时</p>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">std</span></span></span><br><span class="line"><span class="class"> {</span></span><br><span class="line"> <span class="keyword">int</span> age;</span><br><span class="line"> <span class="comment">//注意字符数组的初始化</span></span><br><span class="line"> <span class="keyword">char</span> name[<span class="number">20</span>];</span><br><span class="line"> };</span><br></pre></td></tr></table></figure>
<ul>
<li>结构体初始化</li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">std</span> <span class="title">str</span>;</span></span><br><span class="line">str.age = <span class="number">100</span>;</span><br><span class="line">str.name = <span class="string">"test"</span>;</span><br></pre></td></tr></table></figure>
<ul>
<li>让结构体指针指向结构体</li>
<li>通过结构体指针访问结构体变量的代码与前面相同</li>
</ul>
<p><strong>结构体初始化错误方式</strong></p>
<ul>
<li>字符数组未初始化 会导致栈溢出</li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">std</span></span></span><br><span class="line"><span class="class"> {</span></span><br><span class="line"> <span class="keyword">int</span> age;</span><br><span class="line"> <span class="keyword">char</span> name[];</span><br><span class="line"> };</span><br></pre></td></tr></table></figure>
<ul>
<li>先声明结构体后,一次性初始化结构体全部成员变量</li>
</ul>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">std</span> <span class="title">str</span>;</span></span><br><span class="line">str = {<span class="number">1</span>,<span class="string">"test"</span>};</span><br></pre></td></tr></table></figure>
<p><strong>全部代码如下</strong></p>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><string.h></span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="class"><span class="keyword">struct</span> <span class="title">std</span></span></span><br><span class="line"><span class="class"> {</span></span><br><span class="line"> <span class="keyword">int</span> age;</span><br><span class="line"> <span class="keyword">char</span> *name;</span><br><span class="line"> };</span><br><span class="line"> <span class="comment">//struct std str = {1,"test1"};</span></span><br><span class="line"> <span class="class"><span class="keyword">struct</span> <span class="title">std</span> <span class="title">str</span>;</span></span><br><span class="line"> str.age = <span class="number">100</span>;</span><br><span class="line"> str.name = <span class="string">"test"</span>;</span><br><span class="line"> <span class="class"><span class="keyword">struct</span> <span class="title">std</span> *<span class="title">s</span> = <span class="title">NULL</span>;</span></span><br><span class="line"> s = &str;</span><br><span class="line"> <span class="comment">//strcpy((*s).name,"test");</span></span><br><span class="line"> <span class="comment">//(*s).age = 100;</span></span><br><span class="line"> <span class="comment">//str.name = "test";</span></span><br><span class="line"></span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"name:%s\n"</span>,(*s).name);</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"age:%d\n"</span>,(*s).age);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
]]></content>
<categories>
<category>C</category>
</categories>
<tags>
<tag>C</tag>
</tags>
</entry>
<entry>
<title>MyBatis</title>
<url>/posts/f1de/</url>
<content><![CDATA[]]></content>
<categories>
<category>后端框架</category>
</categories>
<tags>
<tag>MyBatis</tag>
</tags>
</entry>
<entry>
<title>Java集合</title>
<url>/posts/5257/</url>
<content><![CDATA[<h1 id="集合分类:"><a href="#集合分类:" class="headerlink" title="集合分类:"></a>集合分类:</h1><p><strong>List,Set,Map三者的区别</strong></p>
<p><strong>List(顺序)</strong>: List接⼝存储⼀组不唯⼀(可以有<strong>多个元素引⽤相同的对象</strong>),<strong>有序</strong>的对象</p>
<p><strong>Set(不重复):</strong> 不允许重复的集合。<strong>不会有多个元素引⽤相同的对象。</strong></p>
<p><strong>Map(键Key):</strong> 使⽤<code>键值对</code>存储。Map会维护与Key有关联的值。<strong>两个Key可以引⽤相</strong></p>
<p><strong>同的对象</strong>,但Key不能重复,典型的Key是String类型,但也可以是任何对象。</p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn/img/20200703152229.png" alt="image-20200703152225014"></p>
<h2 id="List"><a href="#List" class="headerlink" title="List"></a>List</h2><h3 id="1-1ArrayList"><a href="#1-1ArrayList" class="headerlink" title="1.1ArrayList"></a>1.1ArrayList</h3><p><code>ArrayList</code>实现了<strong>长度可变的数组</strong>,数组<strong>元素类型为Object类型</strong>,即<strong>可以存放所有类型数据</strong>,内存中<strong>分配连续的空间</strong>。</p>
<ul>
<li><p><strong>遍历元素</strong>和<strong>随机访问元素</strong>的效率比较高 </p>
</li>
<li><p>构造ArrayList时;若使用<strong>默认构造函数</strong>,则ArrayList的<strong>默认容量大小是10。</strong></p>
</li>
<li><p>ArrayList<strong>容量不足以容纳全部元素</strong>时,ArrayList会<strong>重新设置容量</strong>:<strong>新的容量=“(原始容量x3)/2 + 1”。</strong></p>
</li>
<li><p>ArrayList实现``java.io.Serializable`的方式。当<strong>写入到输出流</strong>时,<strong>先写入“容量”</strong>,<strong>再依次写入“每一个元素”</strong>;当<strong>读出输入流</strong>时,<strong>先读取“容量”,再依次读取“每一个元素</strong></p>
</li>
</ul>
<p> <strong>内存图解</strong></p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn/img/20200703180004.png" alt="image-20200703154835792"></p>
<p><code>ArrayList</code>的常用方法</p>
<p><strong>增加</strong></p>
<ul>
<li><p><code>add();</code> 加入一个元素(Object)</p>
</li>
<li><p><code>addAll();</code> 加入集合元素(Collection)</p>
</li>
<li><p><code>add(index, element);</code>在指定位置添加元素></p>
</li>
</ul>
<p><strong>删除</strong></p>
<ul>
<li><code>remove(int index)</code> 通过索引删除<strong>指定位置</strong>的元素。 </li>
<li><code>remove(Object o)</code> 删除第一次出现的指定元素从这个列表,如果它存在。 </li>
</ul>
<p>注意重载</p>
<ul>
<li><code>removeAll(Collection c)</code> 从这个列表中移除所有元素包含在指定的集合</li>
</ul>
<p><strong>修改</strong></p>
<ul>
<li><code>set(index, element)</code> 取代<strong>指定位置</strong>上的元素</li>
</ul>
<p><strong>查询</strong></p>
<ul>
<li><p><code>size()</code> 查看<strong>集合的长度</strong>:</p>
</li>
<li><p><code>indexOf()</code> 通过索引查询指定元素 <strong>从前往后查</strong></p>
</li>
<li><p><code>lastIndexOf()</code> 通过索引查询指定元素,<strong>从后向前查找</strong></p>
</li>
<li><p><code>contains()</code> 判读集合中<strong>是否包含某个元素</strong></p>
</li>
</ul>
<p><strong>其他方法</strong></p>
<ul>
<li><code>subList(start, end)</code> 截取集合内的元素 (起始索引,结束索引)</li>
</ul>
<p><strong>遍历</strong></p>
<ul>
<li>for循环</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i < arrayList.size(); i++) {</span><br><span class="line"> System.out.println(arrayList.get(i));</span><br><span class="line"> }</span><br></pre></td></tr></table></figure>
<ul>
<li>foreach循环</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">for</span>(Object o:arrayList) {</span><br><span class="line"> System.out.println(o);</span><br><span class="line"> }</span><br></pre></td></tr></table></figure>
<ul>
<li>迭代器<code>Iterator</code></li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line">Iterator iterator = arrayList.iterator();</span><br><span class="line"> <span class="keyword">while</span>(iterator.hasNext()) {</span><br><span class="line"> System.out.println(iterator.next());</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p><strong>遍历ArrayList时,使用随机访问 (通过索引序号访问) 效率最高,而使用迭代器的效率最低</strong></p>
<p>🔗参考链接</p>
<ul>
<li><a href="https://blog.csdn.net/qq_43776742/article/details/91042479" target="_blank" rel="noopener">https://blog.csdn.net/qq_43776742/article/details/91042479</a></li>
</ul>
]]></content>
<categories>
<category>Java</category>
</categories>
<tags>
<tag>Java</tag>
<tag>集合</tag>
</tags>
</entry>
<entry>
<title>KMP算法</title>
<url>/posts/8c51/</url>
<content><![CDATA[<p>KMP算法的应用场景是字符串匹配</p>
<p><strong>问题描述</strong></p>
<blockquote>
<p>有一个字符串 str1= “BBC ABCDAB ABCDABCDABDE”,和一个子串 str2=”ABCDABD”,</p>
<p>现在要判断str1是否含有str2, 如果存在,就返回第一次出现的位置, 如果没有,则返回-1</p>
</blockquote>
<h2 id="暴力破解"><a href="#暴力破解" class="headerlink" title="暴力破解"></a>暴力破解</h2><ul>
<li>将两个字符串分别存入两个字符数组中分别为c1,和c2</li>
</ul>
<p>BBC ABCDAB ABCDABCDABDE</p>
<p><strong>ABCDABD</strong></p>
<p>思路</p>
<p>两个辅助变量为S和T</p>
<p>一个字符一个字符进行匹配,相同时S和T均向后移动一位,直到字符串末尾,不能匹配时,将S移动到</p>
<h2 id="KMP算法"><a href="#KMP算法" class="headerlink" title="KMP算法"></a>KMP算法</h2><p>字符串不进行回溯,移动字串</p>
<p>根据子串编写部分匹配表</p>
<p>编写规则</p>
<p><strong>ABCDABD</strong></p>
<table>
<thead>
<tr>
<th>子串的字符</th>
<th>前缀</th>
<th>后缀</th>
<th>前缀与后缀的最大公共字符数</th>
</tr>
</thead>
<tbody><tr>
<td>A</td>
<td>无</td>
<td>无</td>
<td>0</td>
</tr>
<tr>
<td>AB</td>
<td>A</td>
<td>B</td>
<td>0</td>
</tr>
<tr>
<td>ABC</td>
<td>A,AB</td>
<td>BC,C</td>
<td>0</td>
</tr>
<tr>
<td>ABCD</td>
<td>A,AB,ABC</td>
<td>BCD,CD,D</td>
<td>0</td>
</tr>
<tr>
<td>ABCDA</td>
<td>A,AB,ABC,ABCD</td>
<td>BCDA,CDA,CD,A</td>
<td>1</td>
</tr>
<tr>
<td>ABCDAB</td>
<td>A,AB,ABC,ABCD,ABCDA</td>
<td>BCDAB,CDAB,DAB,AB,B</td>
<td>2</td>
</tr>
</tbody></table>
<p><strong>移动位数 = 以匹配的字符数 - 前缀与后缀的最大公共字符数</strong></p>
]]></content>
<categories>
<category>数据结构和算法</category>
</categories>
<tags>
<tag>C++</tag>
<tag>KMP</tag>
<tag>算法</tag>
</tags>
</entry>
<entry>
<title>make和makefile文件</title>
<url>/posts/bfbe/</url>
<content><![CDATA[<p>make</p>
<p>用处:用来管理多模块程序的的编译和链接,直至生成可执行文件</p>
<p>Clion分模块编译</p>
<p>1.最外层的CmakeLists</p>
<figure class="highlight cmake"><table><tr><td class="code"><pre><span class="line"><span class="keyword">cmake_minimum_required</span>(VERSION <span class="number">3.17</span>)</span><br><span class="line"><span class="keyword">project</span>(Game C)</span><br><span class="line"></span><br><span class="line"><span class="keyword">set</span>(CMAKE_C_STANDARD <span class="number">99</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">add_subdirectory</span>(code/Bird)</span><br><span class="line"><span class="keyword">add_subdirectory</span>(code/Triangle)</span><br><span class="line"><span class="keyword">add_subdirectory</span>(code/public)</span><br></pre></td></tr></table></figure>
<p>2.内层CmakeLists</p>
<figure class="highlight cmake"><table><tr><td class="code"><pre><span class="line"><span class="keyword">add_subdirectory</span>(Bird)</span><br><span class="line"><span class="keyword">add_subdirectory</span>(Triangle)</span><br><span class="line"><span class="keyword">add_subdirectory</span>(public)</span><br></pre></td></tr></table></figure>
<p>3.最内层CmakeLists</p>
<figure class="highlight cmake"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 包含公共库</span></span><br><span class="line"><span class="keyword">include_directories</span>(<span class="variable">${CMAKE_SOURCE_DIR}</span>/code/public)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 生成可执行文件</span></span><br><span class="line"><span class="keyword">add_executable</span>(Bird Bird.c)</span><br><span class="line"><span class="comment"># 链接公共库</span></span><br><span class="line"><span class="keyword">target_link_libraries</span>(Bird Scanf_lib)</span><br></pre></td></tr></table></figure>
<figure class="highlight cmake"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 生成一个静态库,因为所有其他数据结构都会引用这个库</span></span><br><span class="line"><span class="keyword">add_library</span>(Scanf_lib public.c)</span><br></pre></td></tr></table></figure>
]]></content>
<categories>
<category>uncategorized</category>
</categories>
<tags>
<tag>make</tag>
<tag>makefile</tag>
</tags>
</entry>
<entry>
<title>Nginx配置SSL证书</title>
<url>/posts/27ab/</url>
<content><![CDATA[<blockquote>
<p>环境</p>
</blockquote>
<ul>
<li>阿里云 centos7.7</li>
<li>SSL证书</li>
<li>Nginx/1.17.9</li>
<li>一个解析好的域名</li>
<li>Xshell 和 Xftp</li>
</ul>
<p><strong>Nginx安装SSL官网文档:</strong><br><a href="https://help.aliyun.com/document_detail/98728.html?spm=5176.2020520163.0.0.113156a7LfBJvD" target="_blank" rel="noopener">https://help.aliyun.com/document_detail/98728.html?spm=5176.2020520163.0.0.113156a7LfBJvD</a></p>
<p><strong>开始配置</strong></p>
<ul>
<li>在Nginx安装目录(默认Nginx安装目录为/usr/local/nginx/conf)下创建cert目录,并将下载的证书文件和密钥文件拷贝到cert目录中。</li>
</ul>
<p><img src= "/img/loading.gif" data-src="https://i.loli.net/2020/04/30/YEZrqlSAVxCwpFG.png" alt="image.png"></p>
<p><strong>编辑nginx配置文件</strong></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># HTTPS server</span></span><br><span class="line"> server {</span><br><span class="line"> listen 443 ssl;</span><br><span class="line"> server_name www.crow1024.top;</span><br><span class="line"> </span><br><span class="line"> ssl_certificate cert/3816266_www.crow1024.top.pem;</span><br><span class="line"> ssl_certificate_key cert/3816266_www.crow1024.top.key;</span><br><span class="line"> </span><br><span class="line"> ssl_session_cache shared:SSL:1m;</span><br><span class="line"> ssl_session_timeout 5m;</span><br><span class="line"> </span><br><span class="line"> ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;</span><br><span class="line"> ssl_protocols TLSv1 TLSv1.1 TLSv1.2;</span><br><span class="line"> ssl_prefer_server_ciphers on;</span><br><span class="line"> </span><br><span class="line"> location / {</span><br><span class="line"> root html;</span><br><span class="line"> proxy_set_header HOST <span class="variable">$host</span>;</span><br><span class="line"> proxy_set_header X-Forwarded-Proto <span class="variable">$scheme</span>;</span><br><span class="line"> proxy_set_header X-Real-IP <span class="variable">$remote_addr</span>;</span><br><span class="line"> proxy_set_header X-Forwarded-For <span class="variable">$proxy_add_x_forwarded_for</span>; </span><br><span class="line"> proxy_pass http://127.0.0.1:8090;</span><br><span class="line"> index index.html index.htm;</span><br><span class="line"> }</span><br><span class="line"> }</span><br></pre></td></tr></table></figure>
<p><strong>location中注意点</strong></p>
<ul>
<li>http后面没有s</li>
<li>加上halo的默认端口号<br><img src= "/img/loading.gif" data-src="https://i.loli.net/2020/04/30/GYWplMZtP9eNrQH.png" alt="image.png"></li>
</ul>
<p><strong>保存退出切换到sbin目录下</strong></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">[root@crow ~]<span class="comment"># cd /usr/local/nginx/sbin</span></span><br><span class="line"><span class="comment"># 停止nginx服务</span></span><br><span class="line">./nginx -s stop</span><br><span class="line"><span class="comment"># 启动nginx</span></span><br><span class="line">./nginx</span><br></pre></td></tr></table></figure>
<p><strong>打开浏览器就可以直接通过域名访问</strong></p>
]]></content>
<categories>
<category>服务器</category>
</categories>
<tags>
<tag>服务器</tag>
</tags>
</entry>
<entry>
<title>内存分区模型</title>
<url>/posts/a132/</url>
<content><![CDATA[<p>C++程序在执行时,将内存大方向划分为<strong>4个区域</strong></p>
<ul>
<li><code>代码区</code>:存放函数体的<strong>二进制代码</strong>,由<strong>操作系统进行管理</strong></li>
<li><code>全局区</code>:存放<strong>全局变量</strong>和<strong>静态变量</strong>以及<strong>常量</strong></li>
<li><code>栈区</code>:<strong>编译器自动分配释放</strong>, 存放<strong>函数的参数值</strong>,<strong>局部变量</strong>等</li>
<li><code>堆区</code>:<strong>手动分配和释放,没有手动释放</strong>,程序结束时<strong>由操作系统回收</strong></li>
</ul>
<p><strong>内存四区意义:</strong></p>
<p><strong>不同区域存放的数据,赋予不同的生命周期</strong>, 便于开发程序</p>
<h2 id="程序运行前"><a href="#程序运行前" class="headerlink" title="程序运行前"></a>程序运行前</h2><p>程序编译后,生成了exe可执行程序,<strong>未执行该程序前</strong>分为<strong>两个区域</strong></p>
<p><strong>代码区:</strong></p>
<ul>
<li>存放 CPU 执行的<strong>机器指令(二进制代码)</strong></li>
<li>代码区是<strong>共享</strong>的,共享的目的是<strong>对于频繁被执行的程序,内存中有一份代码即可</strong></li>
<li>代码区是<strong>只读</strong>的,使其只读的原因是<strong>防止程序意外地修改了它的指令</strong></li>
</ul>
<p><strong>全局区:</strong></p>
<ul>
<li><code>全局变量</code>和<code>静态变量</code>存放位置</li>
<li>全局区还包含了<code>常量区</code>, <code>字符串常量</code>和<code>其他常量</code>也存放在此.</li>
<li><strong>该区域的数据在程序结束后由操作系统释放</strong></li>
</ul>
<p><strong>🌰举例:</strong></p>
<figure class="highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><iostream></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="comment">//全局变量</span></span><br><span class="line"><span class="keyword">int</span> g_a = <span class="number">10</span>;</span><br><span class="line"><span class="keyword">int</span> g_b = <span class="number">10</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//全局常量</span></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> c_g_a = <span class="number">10</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> c_g_b = <span class="number">10</span>;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="comment">//局部变量</span></span><br><span class="line"> <span class="keyword">int</span> a = <span class="number">10</span>;</span><br><span class="line"> <span class="keyword">int</span> b = <span class="number">10</span>;</span><br><span class="line"></span><br><span class="line"> <span class="comment">//打印地址</span></span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"局部变量a地址为: "</span> << &a << <span class="built_in">endl</span>;</span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"局部变量b地址为: "</span> << &b << <span class="built_in">endl</span>;</span><br><span class="line"></span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"全局变量g_a地址为: "</span> << &g_a << <span class="built_in">endl</span>;</span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"全局变量g_b地址为: "</span> << &g_b << <span class="built_in">endl</span>;</span><br><span class="line"></span><br><span class="line"> <span class="comment">//静态变量</span></span><br><span class="line"> <span class="keyword">static</span> <span class="keyword">int</span> s_a = <span class="number">10</span>;</span><br><span class="line"> <span class="keyword">static</span> <span class="keyword">int</span> s_b = <span class="number">10</span>;</span><br><span class="line"></span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"静态变量s_a地址为: "</span> << &s_a << <span class="built_in">endl</span>;</span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"静态变量s_b地址为: "</span> << &s_b << <span class="built_in">endl</span>;</span><br><span class="line"></span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"字符串常量地址为: "</span> << &<span class="string">"hello world"</span> << <span class="built_in">endl</span>;</span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"字符串常量地址为: "</span> << &<span class="string">"hello world1"</span> << <span class="built_in">endl</span>;</span><br><span class="line"></span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"全局常量c_g_a地址为: "</span> << &c_g_a << <span class="built_in">endl</span>;</span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"全局常量c_g_b地址为: "</span> << &c_g_b << <span class="built_in">endl</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">const</span> <span class="keyword">int</span> c_l_a = <span class="number">10</span>;</span><br><span class="line"> <span class="keyword">const</span> <span class="keyword">int</span> c_l_b = <span class="number">10</span>;</span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"局部常量c_l_a地址为: "</span> << &c_l_a << <span class="built_in">endl</span>;</span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"局部常量c_l_b地址为: "</span> << &c_l_b << <span class="built_in">endl</span>;</span><br><span class="line"></span><br><span class="line"> system(<span class="string">"pause"</span>);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p><strong>打印结果:</strong></p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">局部变量a地址为: 0x66fe1c</span><br><span class="line">局部变量b地址为: 0x66fe18</span><br><span class="line">全局变量g_a地址为: 0x404010</span><br><span class="line">全局变量g_b地址为: 0x404014</span><br><span class="line">静态变量s_a地址为: 0x404018</span><br><span class="line">静态变量s_b地址为: 0x40401c</span><br><span class="line">字符串常量地址为: 0x405096</span><br><span class="line">字符串常量地址为: 0x4050a2</span><br><span class="line">全局常量c_g_a地址为: 0x405000</span><br><span class="line">全局常量c_g_b地址为: 0x405004</span><br><span class="line">局部常量c_l_a地址为: 0x66fe14</span><br><span class="line">局部常量c_l_b地址为: 0x66fe10</span><br></pre></td></tr></table></figure>
<p><strong>总结:</strong></p>
<ul>
<li>C++中在程序运行前分为<code>全局区</code>和<code>代码区</code></li>
<li><code>代码区</code>特点是<strong>共享和只读</strong></li>
<li><code>全局区</code>中存放<code>全局变量</code>、<code>静态变量</code>、<code>常量</code></li>
<li><code>常量区</code>中存放 <code>const修饰的全局常量</code> 和 <code>字符串常量</code></li>
</ul>
<h2 id="程序运行后"><a href="#程序运行后" class="headerlink" title="程序运行后"></a>程序运行后</h2><p><strong>栈区:</strong></p>
<ul>
<li>编译器<strong>自动分配释放内存</strong>, 存放函数的<code>参数值</code>,<code>局部变量</code>等</li>
<li>注意事项:<strong>不要返回局部变量的地址,栈区开辟的数据由编译器自动释放</strong></li>
</ul>
<p><strong>🌰举例:</strong></p>
<figure class="highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">int</span> * <span class="title">func</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">int</span> a = <span class="number">10</span>;</span><br><span class="line"> <span class="keyword">return</span> &a;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> *p = func();</span><br><span class="line"> <span class="comment">//第一次可以打印吃结果的原因:编译器对数据进行了保留</span></span><br><span class="line"> <span class="built_in">cout</span> << *p << <span class="built_in">endl</span>;</span><br><span class="line"> <span class="comment">//再次使用指针在内存中对数据进行操作时,数据已经消失</span></span><br><span class="line"> <span class="built_in">cout</span> << *p << <span class="built_in">endl</span>;</span><br><span class="line"></span><br><span class="line"> system(<span class="string">"pause"</span>);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p><strong>堆区:</strong></p>
<ul>
<li><strong>手动分配释放</strong>,没有释放,<strong>程序结束时由操作系统回收</strong></li>
<li>C++中主要利用<strong>new在堆区开辟内存</strong></li>
</ul>
<p><strong>🌰举例:</strong></p>
<figure class="highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">int</span>* <span class="title">func</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">int</span>* a = <span class="keyword">new</span> <span class="keyword">int</span>(<span class="number">10</span>);</span><br><span class="line"> <span class="keyword">return</span> a;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> *p = func();</span><br><span class="line"></span><br><span class="line"> <span class="built_in">cout</span> << *p << <span class="built_in">endl</span>;</span><br><span class="line"> <span class="built_in">cout</span> << *p << <span class="built_in">endl</span>;</span><br><span class="line"> </span><br><span class="line"> system(<span class="string">"pause"</span>);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p><strong>总结:</strong></p>
<ul>
<li>堆区数据<strong>手动管理开辟和释放</strong></li>
<li>堆区数据利用<strong>new关键字进行开辟内存</strong></li>
</ul>
<h2 id="new操作符"><a href="#new操作符" class="headerlink" title="new操作符"></a>new操作符</h2><ul>
<li>C++中利用<code>new</code>操作符在堆区开辟数据</li>
<li>堆区开辟的数据,由程序员手动开辟,手动释放,释放利用操作符 <code>delete</code></li>
<li>语法:<code>new 数据类型</code></li>
<li><strong>new创建的数据,会返回该数据对应的类型的指针</strong></li>
</ul>
<p><strong>🌰举例:</strong>基本语法</p>
<figure class="highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">int</span>* <span class="title">func</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">int</span>* a = <span class="keyword">new</span> <span class="keyword">int</span>(<span class="number">10</span>);</span><br><span class="line"> <span class="keyword">return</span> a;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> *p = func();</span><br><span class="line"></span><br><span class="line"> <span class="built_in">cout</span> << *p << <span class="built_in">endl</span>;</span><br><span class="line"> <span class="built_in">cout</span> << *p << <span class="built_in">endl</span>;</span><br><span class="line"></span><br><span class="line"> <span class="comment">//利用delete释放堆区数据</span></span><br><span class="line"> <span class="keyword">delete</span> p;</span><br><span class="line"></span><br><span class="line"> <span class="comment">//cout << *p << endl; //报错,释放的空间不可访问</span></span><br><span class="line"></span><br><span class="line"> system(<span class="string">"pause"</span>);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p><strong>🌰举例:</strong>:开辟数组</p>
<figure class="highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="comment">//堆区开辟数组</span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span>* arr = <span class="keyword">new</span> <span class="keyword">int</span>[<span class="number">10</span>];</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i < <span class="number">10</span>; i++)</span><br><span class="line"> {</span><br><span class="line"> arr[i] = i + <span class="number">100</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i < <span class="number">10</span>; i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">cout</span> << arr[i] << <span class="built_in">endl</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">//释放数组 delete 后加 []</span></span><br><span class="line"> <span class="keyword">delete</span>[] arr;</span><br><span class="line"></span><br><span class="line"> system(<span class="string">"pause"</span>);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p> <strong>内存图解</strong></p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn/img/20200712201259.png" alt="image-20200712200817949"></p>
<h2 id="参考链接"><a href="#参考链接" class="headerlink" title="参考链接"></a>参考链接</h2><div class="btn-center">
<a class="btn-beautify button--animated outline green larger" href="https://www.bilibili.com/video/BV1et411b73Z?p=85" target="_blank" rel="noopener" title="黑马程序员C++教程"><i class="far fa-hand-point-right fa-fw"></i> 黑马程序员C++教程 </a>
</div>
]]></content>
<categories>
<category>C++</category>
</categories>
<tags>
<tag>C++</tag>
<tag>内存分区模型</tag>
</tags>
</entry>
<entry>
<title>十大排序算法</title>
<url>/posts/564c/</url>
<content><![CDATA[<h2 id="插入排序"><a href="#插入排序" class="headerlink" title="插入排序"></a>插入排序</h2><h3 id="直接插入排序"><a href="#直接插入排序" class="headerlink" title="直接插入排序"></a>直接插入排序</h3><p><strong>插入排序法思想</strong>:</p>
<p>把 n 个待排序的元素看成为一个<code>有序表</code>和一个<code>无序表</code>,开始时<strong>有序表中只包含一个元素</strong>,<strong>无序表中包含有 n-1 个元素个元素</strong>,</p>
<p><strong>排序过程</strong></p>
<p>每次从无序表中取出第一个元素,把它的排序码依次与有序表元素的排序码进行比较,将它插入到有序表中的适当位置,使之成为新的有序表。</p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn/img/20200826153417.png" alt="image-20200826152835050"></p>
<ul>
<li>选取数组的第一个元素为基准值,作为有序部分的第一个元素</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">int</span> insertVal = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">int</span> insertIndex = <span class="number">0</span>;</span><br></pre></td></tr></table></figure>
<ul>
<li>遍历寻找无序部分的元素,跟有序部分的元素进行比较,确定元素应该插入的位置</li>
</ul>
<figure class="highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="keyword">for</span>(i=<span class="number">1</span>; i<n; i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//找到要插入的位置</span></span><br><span class="line"> <span class="keyword">for</span>(j=<span class="number">0</span>; j<i; j++)</span><br><span class="line"> {</span><br><span class="line"> ....</span><br><span class="line"> }</span><br><span class="line"> }</span><br></pre></td></tr></table></figure>
<ul>
<li>插入元素,移动插入位置后的元素</li>
</ul>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="希尔排序"><a href="#希尔排序" class="headerlink" title="希尔排序"></a>希尔排序</h3><figure class="highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><vector></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><cstdlib></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><ctime></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">shellSort</span><span class="params">(<span class="built_in">vector</span><<span class="keyword">int</span>>& <span class="built_in">array</span>)</span></span>{</span><br><span class="line"> <span class="comment">//n为数组长度</span></span><br><span class="line"> <span class="keyword">int</span> n = <span class="built_in">array</span>.<span class="built_in">size</span>();</span><br><span class="line"> <span class="comment">//将数组按照步长分为gap个小组,每个小组的第一个数字加上步长得到第二个数字的下标</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> gap = n / <span class="number">2</span>; gap >= <span class="number">1</span>; gap /= <span class="number">2</span>){</span><br><span class="line"> <span class="comment">//每个小组内使用插入排序</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i = gap; i < n; i++){</span><br><span class="line"> <span class="comment">// 使用插入排序算法,将元素依次插入所在小组的已排序列表中</span></span><br><span class="line"> <span class="comment">// 待插入元素</span></span><br><span class="line"> <span class="keyword">int</span> itermToInsert = <span class="built_in">array</span>[i];</span><br><span class="line"> <span class="keyword">int</span> j = i - gap;</span><br><span class="line"> <span class="comment">//每个小组的第一个数字和末尾数字进行比较</span></span><br><span class="line"> <span class="keyword">while</span> (j >= <span class="number">0</span> && <span class="built_in">array</span>[j] >= itermToInsert){</span><br><span class="line"> <span class="comment">//小组内的第一个数字大于末尾数字,则进行交换</span></span><br><span class="line"> <span class="built_in">array</span>[j + gap] = <span class="built_in">array</span>[j];</span><br><span class="line"> <span class="comment">//j -= gap 为了跳出当前循环,进行下一组元素的交换</span></span><br><span class="line"> j -= gap;</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">array</span>[j + gap] = itermToInsert;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Print</span><span class="params">(<span class="built_in">vector</span><<span class="keyword">int</span>>& <span class="built_in">array</span>)</span></span>{</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> & it : <span class="built_in">array</span>) {</span><br><span class="line"> <span class="built_in">cout</span> << it << <span class="string">" "</span>;</span><br><span class="line"> }<span class="built_in">cout</span> << <span class="built_in">endl</span>;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="built_in">vector</span><<span class="keyword">int</span>>arr;</span><br><span class="line"> arr.resize(<span class="number">100000</span>);</span><br><span class="line"> srand(time(<span class="literal">NULL</span>));</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i < <span class="number">100000</span>; ++i) {</span><br><span class="line"> arr.push_back(rand()%<span class="number">100000</span>+<span class="number">1</span>);</span><br><span class="line"> }</span><br><span class="line"> shellSort(arr);</span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"The run time is:"</span> << (<span class="keyword">double</span>)clock() /CLOCKS_PER_SEC<< <span class="string">"s"</span> << <span class="built_in">endl</span>;</span><br><span class="line"> Print(arr);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category>数据结构和算法</category>
</categories>
<tags>
<tag>排序</tag>
</tags>
</entry>
<entry>
<title>Win10快捷键</title>
<url>/posts/e5dc/</url>
<content><![CDATA[<p>1.创建虚拟桌面</p>
<p>Win+Alt+D / Win+Tab(可以通过鼠标操作虚拟桌面的创建、切换与删除)</p>
<p>Win+Ctrl+F4 关闭当前虚拟桌面</p>
<p>2.窗口最小化</p>
<p>Win+M 窗口最小化 Win+D 可在最小化全部窗口与恢复全部窗口状态 间自由切换</p>
<p>3.应用切换<br>Ctrl+Alt+Tab显示当前桌面运行的所有应用程序 Ctrl+Tab 切换任务</p>
<p>4.屏幕截图</p>
<p>Win + PrtSc/PrtSc /Win + Shift + S</p>
<p>5.任务管理器</p>
<p>Ctrl+Shift+Esc</p>
<p>6.文件资源管理器</p>
<p>Win+E </p>
<p>7.操作中心</p>
<p>win+A</p>
<p>8.打开设置</p>
<p>Win+I</p>
<h2 id="参考链接"><a href="#参考链接" class="headerlink" title="参考链接"></a>参考链接</h2><div class="btn-center">
<a class="btn-beautify button--animated outline green larger" href="https://www.jb51.net/os/win10/226560.html" target="_blank" rel="noopener" title="Win10快捷键大全"><i class="far fa-hand-point-right fa-fw"></i> Win10快捷键大全 </a>
</div>
]]></content>
<categories>
<category>生产力</category>
</categories>
<tags>
<tag>Win10</tag>
</tags>
</entry>
<entry>
<title>位运算</title>
<url>/posts/ebce/</url>
<content><![CDATA[<h3 id="位运算符以及源码-反码-补码"><a href="#位运算符以及源码-反码-补码" class="headerlink" title="位运算符以及源码,反码,补码"></a>位运算符以及源码,反码,补码</h3><ul>
<li>二进制的最高位是符号位:0表示正数,1表示负数</li>
<li>正数三码合一,均相同</li>
<li><strong>负数</strong>的反码 = 符号位不变,其他位取反(0=>1,1=>0)</li>
<li><strong>负数</strong>的补码 = 反码 + 1</li>
<li>0的补码,原码都是0,+0的反码 = 0000 0000,-0的补码 = 1111 1111;</li>
<li><strong>计算机运算</strong>的时候都是以<strong>补码</strong>的方式来运行 原因:可以将正负数统一起来</li>
</ul>
<table>
<thead>
<tr>
<th>运算规则</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>&:按位与</td>
<td>相同为1,否则为0</td>
</tr>
<tr>
<td>|:按位或</td>
<td>有1为1,否则为0</td>
</tr>
<tr>
<td>^:按位异或</td>
<td>不同为1,否则为0</td>
</tr>
<tr>
<td>~:按位取反</td>
<td>1转换为0,0转换为1</td>
</tr>
</tbody></table>
<p>🌰举两个例子</p>
<p><strong>~2:对2取反</strong></p>
<ul>
<li>1.2是正数三码合一得到补码:</li>
</ul>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">#int占4个字节 1个字节等于8位</span><br><span class="line">补码: 00000000 00000000 00000000 00000010</span><br><span class="line">#进行取反</span><br><span class="line">补码: 11111111 11111111 11111111 11111101</span><br><span class="line">#将取反后得到的补码(11111111 11111111 11111111 11111101)转成源码</span><br><span class="line">#负数的补码 = 反码 + 1</span><br><span class="line">反码: 补码 - 1 = 11111111 11111111 11111111 11111100</span><br><span class="line">#负数的反码 = 符号位不变,其他位取反(0=>1,1=>0)</span><br><span class="line">源码: 10000000 00000000 00000000 00000011</span><br><span class="line">#对2取反的结果是-3</span><br><span class="line">~2 => -3</span><br></pre></td></tr></table></figure>
<blockquote>
<p>代码如下:</p>
</blockquote>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><stdio.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> a = ~<span class="number">2</span>;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"a = %d"</span>,a);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/25/66509c6ebf73a738a3e86da02d1cab4f.png" alt="image-20200625172956190"></p>
<p><strong>2&-3:2对-3进行按位与运算</strong></p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">#获取2的补码</span><br><span class="line">补码: 00000000 00000000 00000000 00000010</span><br><span class="line">#获取-3的源码</span><br><span class="line">源码: 10000000 00000000 00000000 00000011</span><br><span class="line">#负数的反码 = 符号位不变,其他位取反(0=>1,1=>0)</span><br><span class="line">反码: 11111111 11111111 11111111 11111100</span><br><span class="line">#获取-3的补码</span><br><span class="line">#负数的补码 = 反码 + 1</span><br><span class="line">补码: 11111111 11111111 11111111 11111101</span><br><span class="line"></span><br><span class="line">#将2和-3的补码进行运算</span><br><span class="line"> 2的补码: 00000000 00000000 00000000 00000010</span><br><span class="line">-3的补码: 11111111 11111111 11111111 11111101</span><br><span class="line">&: 相同为1,否则为0</span><br><span class="line">#运算结果 为0</span><br><span class="line">00000000 00000000 00000000 00000000</span><br></pre></td></tr></table></figure>
<blockquote>
<p>代码如下:</p>
</blockquote>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><stdio.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> b = <span class="number">2</span> & <span class="number">-3</span>;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"b = %d"</span>,b);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/25/8739d86e6f646cbbc0daa0318c2a2dfb.png" alt="image-20200625175424053"></p>
<h3 id="移位运算符"><a href="#移位运算符" class="headerlink" title="移位运算符"></a>移位运算符</h3><p><strong>算术左移<<:</strong> <strong>符号位不变,低位补0</strong> </p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">3 << 2,则是将数字3左移2位</span><br><span class="line">#首先把3转换为二进制数字</span><br><span class="line">00000000 00000000 00000000 00000011</span><br><span class="line">#把该数字高位(左侧)的两个零移出,其他的数字都朝左平移2位,最后在低位(右侧)的两个空位补零</span><br><span class="line">#转换为十进制是12</span><br><span class="line">0000 0000 0000 0000 0000 0000 0000 1100</span><br></pre></td></tr></table></figure>
<blockquote>
<p>代码如下:</p>
</blockquote>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><stdio.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> c = <span class="number">3</span> << <span class="number">2</span>;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"c = %d"</span>,c);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/25/ae4bc9b8187b6a5973852f953ff48973.png" alt="image-20200625200949845"></p>
<p><strong>算术右移>></strong>: <strong>低位移出(舍弃),高位的空位补符号位,即正数补零,负数补1。</strong></p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">11 >> 2,则是将数字11右移2位</span><br><span class="line">#首先把11转换为二进制数字</span><br><span class="line">00000000 00000000 00000000 00001011</span><br><span class="line">#把低位的最后两个数字移出,因为该数字是正数,所以在高位补零</span><br><span class="line">#转换为十进制是2</span><br><span class="line">00000000 00000000 00000000 00000010</span><br><span class="line"></span><br><span class="line">-1 >> 2</span><br><span class="line">#获取-1的源码</span><br><span class="line">10000000 00000000 00000000 00000001</span><br><span class="line">#源码=>反码</span><br><span class="line">11111111 11111111 11111111 11111110</span><br><span class="line">#反码=>补码</span><br><span class="line">11111111 11111111 11111111 11111111</span><br><span class="line">#移动两位后 (补码)</span><br><span class="line">11111111 11111111 11111111 11111111</span><br><span class="line">#补码=>源码</span><br><span class="line">#转换为十进制是-1</span><br><span class="line">10000000 00000000 00000000 00000001</span><br></pre></td></tr></table></figure>
<blockquote>
<p>代码如下:</p>
</blockquote>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> d = <span class="number">11</span> >> <span class="number">2</span>;</span><br><span class="line"> <span class="keyword">int</span> e = <span class="number">-1</span> >> <span class="number">2</span>;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"d = %d e = %d"</span>,d,e);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/06/25/3499348d49718a15382fb71f28120f1d.png" alt="image-20200625201030080"></p>
<ul>
<li><h2 id="参考链接"><a href="#参考链接" class="headerlink" title="参考链接"></a>参考链接</h2></li>
</ul>
<div class="btn-center">
<a class="btn-beautify button--animated outline green larger" href="https://www.bilibili.com/video/BV1qJ411z7Hf?p=57" target="_blank" rel="noopener" title="尚硅谷C语言入门"><i class="far fa-hand-point-right fa-fw"></i> 尚硅谷C语言入门 </a>
<a class="btn-beautify button--animated outline green larger" href="https://baike.so.com/doc/23743705-24299622.html" target="_blank" rel="noopener" title="360百科"><i class="far fa-hand-point-right fa-fw"></i> 360百科 </a>
</div>]]></content>
<categories>
<category>C</category>
</categories>
<tags>
<tag>计算机基础知识</tag>
<tag>位运算</tag>
</tags>
</entry>
<entry>
<title>函数</title>
<url>/posts/5409/</url>
<content><![CDATA[<h2 id="函数的初步了解"><a href="#函数的初步了解" class="headerlink" title="函数的初步了解"></a>函数的初步了解</h2><ul>
<li><p>为完成某一功能的<strong>程序指令(语句)的集合</strong>称为<code>函数</code></p>
</li>
<li><p>在C语言中,函数分为:<code>自定义函数</code>、<code>系统函数</code></p>
<ul>
<li>C语言在线手册 <a href="http://www.dba.cn/book/c/CJiChuJiaoCheng/CJiBenYuFa.html" target="_blank" rel="noopener">http://www.dba.cn/book/c/CJiChuJiaoCheng/CJiBenYuFa.html</a></li>
</ul>
</li>
<li><p>函数还有其它名称,方法等</p>
</li>
</ul>
<p><strong>函数的基本语法</strong></p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">返回类型 函数名 (形参){</span><br><span class="line"> 执行语句;</span><br><span class="line"> return 返回值;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<ul>
<li><code>形参</code>表示<strong>函数的输入</strong></li>
<li>函数中的<code>执行语句</code> <strong>实现某一功能代码块</strong></li>
<li>函数可以有返回值,也可以没有,如果没有返回值,返回类型声明为void</li>
</ul>
<h2 id="头文件"><a href="#头文件" class="headerlink" title="头文件"></a>头文件</h2><p><strong>需求</strong>:实际开发中<strong>需要在不同文件中调用其他文件中的函数</strong></p>
<p><strong>基本概念</strong></p>
<ul>
<li><p><code>头文件</code>是<strong>扩展名为h</strong>的文件,包含了<code>C函数声明</code>和<code>宏定义</code>,<strong>被多个源文件中引用共享</strong>。</p>
</li>
<li><p>头文件的类型的开发者<strong>自己编写的头文件</strong>和<strong>C标准库自带的头文件</strong></p>
</li>
<li><p>程序中要使用头文件,需要使用<code>C预处理指令#include</code>来引用。<code>stdio. h</code>头文件,是C标准库自带的头文件</p>
</li>
<li><p>文件包含命令(<code>#include</code>),用来引入对应的头文件(h文件)。#include的<strong>处理过程</strong>是将<strong>头文件的内容插入到该命令所在的位置</strong>,使得<code>头文件</code>和<code>当前源文件</code><strong>连接成一个源文件</strong>,与复制粘贴的效果相同。直接在源文件中复制头文件的内容,容易出错,特别在程序是由多个源文件组成的时候。</p>
</li>
<li><p>所有的<code>常量</code>、<code>宏</code>、<code>系统全局变量</code>和<code>函数原型</code>写在<code>头文件</code>中,需要的时候随时再引用头文件</p>
</li>
</ul>
<p> <strong>工作原理图</strong></p>
<p><img src= "/img/loading.gif" data-src="https://cdn.jsdelivr.net/gh/L0serH4/mycdn@master/2020/07/08/400f7ef8cad9d26182ce82e0a80624f1.png" alt="image-20200708163738567"></p>
<ul>
<li>func.h头文件和func.c源文件<strong>名称一般相同</strong>为了使用</li>
</ul>
<p><strong>头文件的注意事项和细节说明</strong></p>
<ul>
<li><p><strong>引用头文件相当于复制头文件的内容,注意路径问题</strong></p>
</li>
<li><p>C语言中 include<>与 include””的区别include<> :</p>
<ul>
<li><code>include<></code>: 引用的是编译器的类库路径里面的头文件,用于<strong>引用系统头文件</strong></li>
<li><code>include””</code>:引用的是程序<strong>目录的相对路径中的头文件</strong>,</li>
<li>如果在<strong>程序目录</strong>没有找到引用的头文件则到<strong>编译器的类库路径</strong>的目录下找该头文件,</li>
<li>引用<strong>系统头文件</strong>,两种形式·都可以,include<>效率</li>
<li>引用<strong>用户头文件</strong>,只能使用 include””</li>
</ul>
</li>
<li><p>一个#include命令只能包含一个头文件,多个头文件需要多个# include命令</p>
</li>
<li><p>同一个头文件如果被多次引入,<strong>多次引入的效果和一次引入的效果相同</strong>,因为<strong>头文件在代码层面有防止重复引入的机制</strong></p>
</li>
<li><p>在一个被包含的文件.c中又可以包含另一个文件头文件.h</p>
</li>
<li><p>不管是<code>标准头文件</code>,还是<code>自定义头文件</code>,都<strong>只能包含变量和函数的声明</strong>,<strong>不能包含定义</strong>,否则在<strong>多次引入时会引起重复定义错误</strong></p>
</li>
</ul>
<h2 id="函数的调用机制"><a href="#函数的调用机制" class="headerlink" title="函数的调用机制"></a>函数的调用机制</h2><p>函数调用的规则适用于: <code>java</code>,<code>c++</code>,<code>php</code>等)</p>
<ul>
<li>当调用(执行)一个函数时,就会开辟一个独立的空间(栈)</li>
<li>每个栈空间是相互独立</li>
<li>当函数执行完毕后,会返回到调用函数位置,继续执行</li>
<li>函数有返回值,将返回值赋给接收的变量 当一个函数返回后,该函数对应的栈空间也就销毀</li>
</ul>
<h2 id="函数的递归调用"><a href="#函数的递归调用" class="headerlink" title="函数的递归调用"></a>函数的递归调用</h2><p><strong>一个函数在函数体内又调用了函数本身,称为递归调用</strong></p>
<ul>
<li><p>执行一个函数时,就创建一个新的受保护的独立空间(新函数栈)</p>
</li>
<li><p>函数的局部变量是独立的,不会相互影响</p>
</li>
<li><p>递归必须向退出递归的条件逼近,否则就是无限递归,造成栈溢出(StackOverFlow)</p>
</li>
<li><p>当一个函数执行完毕,或者遇到 return,就会返回,将结果返回给调用处</p>
</li>
</ul>
<p>🌰<strong>举例</strong></p>
<p>求出斐波那契数1,1,2,3,5,8,13.求整数n对应的斐波那契数</p>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">fbn</span><span class="params">(<span class="keyword">int</span> n)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(n=<span class="number">1</span> || n==<span class="number">2</span>){</span><br><span class="line"> <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">return</span> fbn(n<span class="number">-1</span>)+ fbn(n<span class="number">-2</span>);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> res = fbn(<span class="number">10</span>);</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"res = %d"</span>,res);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>有一堆桃子,猴子第一天吃了其中的一半,并再多吃了一个,以后每天猴子都吃其中的一半,然后再多吃一个。当到第十天时,想再吃时(还没吃),发现只有1个桃子了。求最初多少桃子?</p>
<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">peach</span><span class="params">(<span class="keyword">int</span> day)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(day=<span class="number">10</span>){</span><br><span class="line"> <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line"> } <span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">return</span> (peach(day+<span class="number">1</span>)+<span class="number">1</span>)*<span class="number">2</span>;</span><br><span class="line"> } </span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="comment">//分析过程</span></span><br><span class="line"> <span class="comment">//1.day=10有1个桃子</span></span><br><span class="line"> <span class="comment">//2.day=9有(day10+1)*2=(1+1)*2=4</span></span><br><span class="line"> <span class="comment">//3.day=8 (day9+1)*2=(4+1)*2=10</span></span><br><span class="line"> <span class="keyword">int</span> peachUm = peach(<span class="number">1</span>);</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"第一天有%d个桃子"</span>,peachUm);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>