C语言概述node
做者:尹正杰mysql
版权声明:原创做品,谢绝转载!不然将追究法律责任。linux
一.什么是C语言程序员
一提到语言这个词语,天然会想到的是像英语,汉语等这样的天然语言,由于它是人和人交换信息不可缺乏的工具。 而今天计算机广泛了咱们生活的每个角落,除了人和人的相互交流以外,咱们必须和计算机交流。 用什么的说明样的方式和计算机最直接交流呢?人们天然想到的是最古老也是最方便的方式,即语言,而C语言就是人和计算机交流的一种语言。 语言用来交流沟通。有一方说,有另外一方听,必须有两房参与,这是语言最重要的功能: (1)说的一方传递消息,听的一方接收信息; (2)说的一方下达指令,听的一方遵照命令作事情; 语言是人和人交流,C语言是人和机器交流。只是,人能够不听另一我的,可是,计算机是无条件服从。、
语言有独特的语法规则和定义,双方必须遵照这些规则和定义才能实现真正的交流。
二.计算机介绍面试
1>.计算机结构组成sql
2>. 计算机系统组成数据库
3>.程序和指令编程
(1)指令是对计算机进行程序控制的最小单位。
(2)全部指令的集合称为计算机的指令系统。
(3)程序是为完成一项特定任务而用某种语言编写的一组指令序列。
三.语言的发展历程缓存
1>.机器语言服务器
计算机的大佬或者说心脏就是CPU,它控制整个计算机的运做。每种CPU,都有本身的指令系统。这个指令系统,就是CPU的机器语言。
机器语言是一组由0和1系列组成的指令码,这些指令码,是CPU制做厂商规定出来的,而后发布出来,请程序员遵照。
要让计算机干活,就得用机器语言(二进制数)去命名它。这样的命令,不是一条两条,而是上百条。并且不一样型号的计算机其机器语言是不相互通的,按照一种计算机的机器指令编程的程序,不能再另外一种计算机上执行。
2>.汇编语言和编译器
机器语言编程时不是很使人烦恼呢,终于出现了汇编语言,就是一些标识符取代0和1.一门人类比较轻松认识的编程语言。
只是这门语言计算机并不认识,因此人类还不能用这门语言命令计算机作事情。这正如如何才能让中国人说的话美国人明白呢?那天然就是翻译啦!
因此,有一类专门的程序,既认识机器语言,有认识汇编语言,也就是翻译器,将标识符转换成0与1,知道怎么把汇编语言翻译成机器语言。
3>.高级语言
汇编语言和机器语言都是面向机器的,机器不一样,语言也不一样。既然有办法让汇编语言翻译成机器语言,难道就不能让其余更人性化的语言翻译成机器语言吗?
1954年,Fortran语言出现了,其后相机出现了其余相似语言。这批语言,使程序员拜托了计算机硬件的限制,把主要精力放在程序设计上,不在关注底层的计算机承硬件。这类语言,称为高级语言。
一样的,高级语言要被计算机执行,也须要一个翻译程序将其翻译成机器语言,这就是编译程序,简称编译器。
这类高级语言解决问题的方法是分析出解决问题所须要的步骤,把程序看做是数据被加工的过程。基于这类方法的程序设计语言称为面向过程的语言。C语言就是这种面向过程的程序设计语言。
4>.语言的层次
5>. 语言进化史
四.为何要学习C语言
1>.C语言特色
优势:
(1)代码量小;
(2)执行速度快;
(3)功能强大;
(4)编程自由
缺点:
(1)写代码实现周期长;
(2)可移植性较差;
(3)对于自由,经验不足易出错;
(4)对平台库依赖较多;
2>.学习C语言理由
(1)全部大学理工科必修课程; (2)名企,外企,高薪程序员面试必考; (3)写外挂,作黑客必须掌握的语言; (4)学习数据结构,C++的基石; (5)绝对重要的基石语言,Unix,Linux,Java,C++,C#底层实现都考C; 咱们能够比较狂妄的说,学会C/C++,走遍全球都不怕,哈哈哈~
3>.C语言领用领域
C语言的应用极为普遍,从网站后台,到底层操做系统,从多媒体应用到大型网络游戏,都可以使用C语言来开发: (1)C语言能够写网站后台程序; (2)C与能够专门针对某个主题写出功能强大的程序库; (3)C语言能够写出大型游戏引擎; (4)C语言能够写出另外一个语言来; (5)C语言能够写操做系统和驱动程序,而且只能用C语言编写; (6)任何设备只要配置微处理器,都支持C语言。从微波炉到手机,都是C语言技术来推进的。
接下来咱们来讲一下互联网比较火的行业,各个语言的应用范围:
(1)嵌入式
C打包天下,极少许汇编。
(2)Web开发
绝大部分Javascript,PHP和商量ASP,JSP,最近Python也加入了这一领域。
(3)高性能服务
Apache,Nginx,Memcached,Redis等等高性能Web服务器和数据库都是纯C开发。
(4)分布式应用
Java,Python的天下。
(5)游戏服务器
C,C++和Lua脚本。
(6)并行计算:
Java,Golang,Erlang,C对接Go语言很是方便。
(7)游戏引擎
C++和脚本。
(8)游戏逻辑
脚本语言。
(9)移动开发
Java,Obj-C/Swift。
(10)桌面开发
C++,Qt+Script,C#都能作出漂亮的跨平台界面。
(11)操做系统
C的天下
(12)虚拟技术
QEMU,KVM,Xen都是纯C开发。
(13)数据库
C的天下
(14)编译器
C,C++并存
(15)大数据
Java的天下,固然用Python也能够调用大数据组件的一些API,可是不少大数据开源软件都是用Java实现的,固然C++在大数据领域中也有贡献,好比由Cloudera公司开源的交互式计算引擎Impala就是使用C++编写的。
(16)云存储
Java,Python包打天下,近年Go语言也参与了好多项目。
4>.C语言的简介
C语言仅有32个关键字,9种控制语句,34中运算符,却能完成无数的功能。
(1)32个关键字(由系统定义,不能重做其余定义)
auto break case char const continue default do double else short signed sizeof static struct volatile
enum extern float for goto if int long register return switch typedef unsigned union void while
(2)9种控制语句
if()~else~
for()~
while()~
do~while()
continue
break
switch
goto
(3)34种运算符
算术运算符 : + - * / % ++ --
关系运算符 : < <= == > >= !=
逻辑运算符 : ! && ||
位运算符 : << >> ~ | ^ &
赋值运算符 : =及其扩展
条件运算符 : ?:
逗号运算符 : ,
指针运算符 : * &
求字节数 : sizeof
强制类型转换 : (类型)
份量运算符 : ->
下标运算符 : []
其它 : ()
5>.学习C语言的技巧
学习编程,先学会面向过程,才能学好面向对象,其它语言的语法有很大一部分都是继承C语言。
理解了指针,地址,更深刻了解语言内部原理。
C语言的英文关键词只有32个,9种控制语句,34种运算符,说实话,C语言只用到初中乃至小学的数学水平。(因此,咱们不要说英语,数学都学很差能学好c么?有志者事竟成!)。
学好C对于其余计算机课程依赖不大。
光看书是不可能学会的,多学多练就能学会。
五.C语言入门程序helloworld
1>.编写C语言代码
[root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# cat hello.c /* 当前代码块为块注释 @author :yinzhengjie blog:http://www.cnblogs.com/yinzhengjie EMAIL:y1053419035@qq.com */ #include <stdio.h> //包含头文件,std是标准库,io分别对应为input和output,导入系统库用"<>"表示,".h"是自定义头文件。总结来讲:导入标准输入输出库,当前行为注释行,用"//"表示行注释 //main是定义主函数,一个程序有且只能有一个主函数,int表明函数的返回值类型,int为整型,注意void表示空类型,即主函数的参数为空。若是参数是void能够省略不写! int main(void) { //这是第一个C语言代码 printf("Hello World\n"); //这是行数的返回值,咱们返回必须和上面定义的int类型要一致!咱们这里返回的是0.若是在主程序中遇到return关键字表明程序结束 return 0; } [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]#
[root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# cat hello.c #C语言的源代码文件是一个普通的文本文件,但扩展名必须是“.c” #include <stdio.h> int main() { //这是第一个C语言代码 printf("Hello World\n"); return 0; } [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]#
[root@node101.yinzhengjie.org.cn ~]# yum -y install gcc Loaded plugins: fastestmirror Determining fastest mirrors epel/x86_64/metalink | 6.5 kB 00:00:00 * base: mirrors.aliyun.com * epel: mirrors.tuna.tsinghua.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com base | 3.6 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 3.4 kB 00:00:00 mysql-connectors-community | 2.5 kB 00:00:00 mysql-tools-community | 2.5 kB 00:00:00 mysql56-community | 2.5 kB 00:00:00 updates | 3.4 kB 00:00:00 zabbix | 2.9 kB 00:00:00 zabbix-non-supported | 951 B 00:00:00 (1/3): epel/x86_64/updateinfo | 1.0 MB 00:00:00 (2/3): updates/7/x86_64/primary_db | 5.0 MB 00:00:01 (3/3): epel/x86_64/primary_db | 6.7 MB 00:00:02 Resolving Dependencies --> Running transaction check ---> Package gcc.x86_64 0:4.8.5-36.el7_6.2 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================================================================================================================== Package Arch Version Repository Size ================================================================================================================================================================================================================================== Installing: gcc x86_64 4.8.5-36.el7_6.2 updates 16 M Transaction Summary ================================================================================================================================================================================================================================== Install 1 Package Total size: 16 M Installed size: 37 M Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. Installing : gcc-4.8.5-36.el7_6.2.x86_64 1/1 Verifying : gcc-4.8.5-36.el7_6.2.x86_64 1/1 Installed: gcc.x86_64 0:4.8.5-36.el7_6.2 Complete! [root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# rpm -qa | grep gcc #查看gcc的安装包 gcc-4.8.5-36.el7_6.2.x86_64 libgcc-4.8.5-36.el7_6.2.x86_64 [root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll total 4 -rw-r--r-- 1 root root 104 May 22 06:13 hello.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# gcc -o hello hello.c #编译后会生成一个名为hello的可执行文件。 [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll total 16 -rwxr-xr-x 1 root root 8440 May 22 06:13 hello -rw-r--r-- 1 root root 104 May 22 06:13 hello.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ./hello #执行编译后的文件 Hello World [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]#
2>.经过gcc编译C代码
(1)gcc编译器介绍 编译器(如vi,记事本)是指我用它来写程序(编辑代码)的,而咱们写的代码语句,电脑是不懂的,咱们须要把它转成电脑能懂的语句,编译器就是这样的转换工具。就是说,咱们用编辑器写程序,由编译器编译后才能够运行! 编译器是将易于编写,阅读和维护的高级计算机语言翻译成计算机能解读,运行的低级机器语言的程序。 gcc(GNU Compiler Collation,GNU编译器套件),是由GNU开发的编程语言编辑器。gcc本来做为GNU操做系统的官方编辑器,先已被大多数类Unix操做系统(如Linux,BSD,Mac OS X等)采纳为标准的编译器,gcc一样适用于微软的Windows。 gcc最初用于编译C语言,随着项目的发展gcc已经成为可以编译C,C++,Java,Ada,fortran,Obejcet C,Object C++,Go语言的编译器你们族。 编译命令格式以下: gcc [-option1] ... <filename> g++ [-option1] ... <filename> 1)命令,选项和源文件之间使用空格分隔 2)一行命令中能够有零个,一个或者多个选项 3)文件名能够包含文件的绝对路径,也可使用相对路径 4)若是命令中不包含输出可执行文件的文件名,可执行文件的文件名会自动生成一个默认名,Linux平台为a.out,Window平台为a.exe gcc,g++编译经常使用选项说明: 1)-o filename 指定生成的输出文件名的filename 2)-E 只进行预处理 3)-S(大写) 只进行预处理和编译 4)-c(小写) 只进行预处理,编译和汇编 (2)Linux平台下编译代码 [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll total 4 -rw-r--r-- 1 root root 848 May 22 06:30 hello.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# gcc hello.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll total 16 -rwxr-xr-x 1 root root 8440 May 22 06:50 a.out -rw-r--r-- 1 root root 848 May 22 06:30 hello.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# 须要注意的是,gcc warning的意思是警告,是有问题,但不影响编译;而error是错误,若是遇到error,那么就不用编译了,先把错误解决掉在进行编译。 (3)Window平台下gcc环境配置 Windows命令行界面下,默认是没有gcc编译器,咱们须要配置一下环境,咱们能够安装Qt,由于Qt是一个集成开发环境,内部集成gcc编译器,配置一下环境变量便可使用gcc。或者你也能够安装Visual Studio软件,他也集成了gcc开发环境。
六.系统调用函数system
1>.system函数的使用
#include <stdlib.h> int system(const char *command) 功能: 在已经运行的程序执行另一个外部程序(系统自带的外部程序或者你自定义的程序) 参数:
外部可执行程序名字 返回值: 若成功,不一样返回值不同
若失败,一般是-1
[root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll total 8 -rw-r--r-- 1 root root 848 May 22 06:30 hello.c -rw-r--r-- 1 root root 158 May 22 07:19 system_demo.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# cat system_demo.c #include <stdlib.h> #include <stdio.h> int main(void) { int value = system("cal"); printf("调用日历工具cal的返回值为:%d\n",value); return 0; } [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# gcc -o system_demo system_demo.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll total 20 -rw-r--r-- 1 root root 848 May 22 06:30 hello.c -rwxr-xr-x 1 root root 8504 May 22 07:19 system_demo -rw-r--r-- 1 root root 158 May 22 07:19 system_demo.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ./system_demo May 2019 Su Mo Tu We Th Fr Sa 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 调用日历工具cal的返回值为:0 [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]#
2>.system返回值不一样系统
C语言全部的库函数调用,只能保证语法是一致的,但不能保证结果是一致的,一样的库函数在不一样的操做系统下执行结果多是同样的,也多是不同的。
在学习Linux发展史中,咱们得知Linux发展离不开POSIX标准,只要符合这个标准的函数,在不一样的系统下执行的结果就能够一直。
Unix和Linux不少函数库都是支持POSIX的,但Window支持的比较差。
若是将Unix代码一直到Linux通常代价很小,若是把Windows代码移植到Unix或者Linux就比较麻烦。
七.C语言编译过程
1>.C语言编译步骤
C代码编译成可执行程序通过4步: (1)预处理 宏定义展开,头文件展开(你会发现展开后会把头文件内容加载进来,文件内容会比你原始代码内容要多),条件编译等,同时将代码中注释删除,这里并不会检查语法。 (2)编译 检查语法,将预处理后文件编译生成汇编文件。 (3)汇编 将汇编文件生成目标文件(二进制文件)。 (4)连接 C语言写的程序是须要依赖各类库的,因此编译以后还须要把库连接到最终的可执行程序中去。
2>.gcc编译过程
[root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll total 8 -rw-r--r-- 1 root root 848 May 22 06:30 hello.c -rw-r--r-- 1 root root 158 May 22 07:19 system_demo.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# cat hello.c /* 当前代码块为块注释 @author :yinzhengjie blog:http://www.cnblogs.com/yinzhengjie EMAIL:y1053419035@qq.com */ #include <stdio.h> //包含头文件,std是标准库,io分别对应为input和output,导入系统库用"<>"表示,".h"是自定义头文件。总结来讲:导入标准输入输出库,当前行为注释行,用"//"表示行注释 //main是定义主函数,一个程序有且只能有一个主函数,int表明函数的返回值类型,int为整型,注意void表示空类型,即主函数的参数为空。若是参数是void能够省略不写! int main(void) { //这是第一个C语言代码 printf("Hello World\n"); //这是行数的返回值,咱们返回必须和上面定义的int类型要一致!咱们这里返回的是0.若是在主程序中遇到return关键字表明程序结束 return 0; } [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]#
[root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll total 8 -rw-r--r-- 1 root root 848 May 22 06:30 hello.c -rw-r--r-- 1 root root 158 May 22 07:19 system_demo.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# gcc -E hello.c -o hello.i [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll -h total 28K -rw-r--r-- 1 root root 848 May 22 06:30 hello.c -rw-r--r-- 1 root root 17K May 22 15:35 hello.i -rw-r--r-- 1 root root 158 May 22 07:19 system_demo.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# wc -l hello.i 847 hello.i [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# wc -l hello.c 18 hello.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]#
[root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll -h total 28K -rw-r--r-- 1 root root 848 May 22 06:30 hello.c -rw-r--r-- 1 root root 17K May 22 15:35 hello.i -rw-r--r-- 1 root root 158 May 22 07:19 system_demo.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# gcc -S hello.i -o hello.s [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll -h total 32K -rw-r--r-- 1 root root 848 May 22 06:30 hello.c -rw-r--r-- 1 root root 17K May 22 15:35 hello.i -rw-r--r-- 1 root root 448 May 22 15:42 hello.s -rw-r--r-- 1 root root 158 May 22 07:19 system_demo.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# cat hello.s .file "hello.c" .section .rodata .LC0: .string "Hello World" .text .globl main .type main, @function main: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl $.LC0, %edi call puts movl $0, %eax popq %rbp .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE0: .size main, .-main .ident "GCC: (GNU) 4.8.5 20150623 (Red Hat 4.8.5-36)" .section .note.GNU-stack,"",@progbits [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]#
[root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll -h total 32K -rw-r--r-- 1 root root 848 May 22 06:30 hello.c -rw-r--r-- 1 root root 17K May 22 15:35 hello.i -rw-r--r-- 1 root root 448 May 22 15:42 hello.s -rw-r--r-- 1 root root 158 May 22 07:19 system_demo.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# gcc -c hello.s -o hello.o [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll -h total 36K -rw-r--r-- 1 root root 848 May 22 06:30 hello.c -rw-r--r-- 1 root root 17K May 22 15:35 hello.i -rw-r--r-- 1 root root 1.5K May 22 15:46 hello.o -rw-r--r-- 1 root root 448 May 22 15:42 hello.s -rw-r--r-- 1 root root 158 May 22 07:19 system_demo.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# wc -l hello.c 18 hello.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# wc -l hello.i 847 hello.i [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# wc -l hello.s 26 hello.s [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# wc -l hello.o 5 hello.o [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]#
[root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll total 36 -rw-r--r-- 1 root root 848 May 22 06:30 hello.c -rw-r--r-- 1 root root 16895 May 22 15:35 hello.i -rw-r--r-- 1 root root 1496 May 22 15:46 hello.o -rw-r--r-- 1 root root 448 May 22 15:42 hello.s -rw-r--r-- 1 root root 158 May 22 07:19 system_demo.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# gcc hello.o -o hello.exe [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll total 48 -rw-r--r-- 1 root root 848 May 22 06:30 hello.c -rwxr-xr-x 1 root root 8440 May 22 15:49 hello.exe -rw-r--r-- 1 root root 16895 May 22 15:35 hello.i -rw-r--r-- 1 root root 1496 May 22 15:46 hello.o -rw-r--r-- 1 root root 448 May 22 15:42 hello.s -rw-r--r-- 1 root root 158 May 22 07:19 system_demo.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]#
[root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ./hello.exe Hello World [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll total 48 -rw-r--r-- 1 root root 848 May 22 06:30 hello.c -rwxr-xr-x 1 root root 8440 May 22 15:49 hello.exe -rw-r--r-- 1 root root 16895 May 22 15:35 hello.i -rw-r--r-- 1 root root 1496 May 22 15:46 hello.o -rw-r--r-- 1 root root 448 May 22 15:42 hello.s -rw-r--r-- 1 root root 158 May 22 07:19 system_demo.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# file hello.c hello.c: C source, UTF-8 Unicode text [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# file hello.i hello.i: C source, ASCII text [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# file hello.s hello.s: ASCII text [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# file hello.o hello.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# file hello.exe hello.exe: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=48e4c11901d54d4bf1b6e3826baf18215e4255e5, not stripped [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]#
3>.查找程序所依赖的动态库(以Linux平台的ldd命令为例,Windows平台可使用Dependency Walker工具)
[root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ll total 48 -rw-r--r-- 1 root root 848 May 22 06:30 hello.c -rwxr-xr-x 1 root root 8440 May 22 15:49 hello.exe -rw-r--r-- 1 root root 16895 May 22 15:35 hello.i -rw-r--r-- 1 root root 1496 May 22 15:46 hello.o -rw-r--r-- 1 root root 448 May 22 15:42 hello.s -rw-r--r-- 1 root root 158 May 22 07:19 system_demo.c [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# ldd hello.exe #使用ldd工具查看我们编译后的文件所依赖的动态库,动态库在Linux平台通常为"*.so" linux-vdso.so.1 => (0x00007ffefa7ab000) libc.so.6 => /lib64/libc.so.6 (0x00007f05d73c4000) /lib64/ld-linux-x86-64.so.2 (0x00007f05d7791000) [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]# [root@node101.yinzhengjie.org.cn /yinzhengjie/code/day001]#
八.CPU内部结构与寄存器(了解)
1>.64位和32位系统区别
(1)寄存器是CPU内部最基本的存储单元; (2)CPU对外是经过总线(地址,控制,数据)来和外部设备交互的,总线的宽度是8位,同时CPU的寄存器也是8位,那么这个CPU就叫8位CPU; (3)若是总线是32位,寄存器也是32位的,那么这个CPU就叫32位CPU; (4)有一种CPU内部的寄存器是32位的,但总线是16位,准32位CPU (5)全部的64位CPU兼容32位的指令,32位要兼容16位的指令,因此在64位的CPU上是能够识别32位的指令; (6)在64位的CPU架构上运行了64位的软件操做系统,那么这个系统是64位; (7)在64位的CPU架构上,运行了32位的软件操做系统,那么这个系统就是32位; (8)64位的软件不能运行在32为的CPU之上,换句话说,32位的CPU是没有办法安装64位的操做系统的。
2>.寄存器名字(了解便可)
3>.寄存器,缓存,内存三种关系
按与CPU远近来分,离得最近的是寄存器,而后缓存(CPU缓存),最后内存。
CPU计算时,先预先把要用的数据从硬盘读取到内存,而后再把即将要用的数据读到寄存器。因而CPU<--->寄存器<--->内存,这就是它们之间的信息交换。 那为何有缓存呢?由于若是总是操做内存的同一地址的数据,就会影响速度,因而就在寄存器和内存之间设置一个缓存。 由于从缓存提取的速度远高于内存。固然缓存的价格确定远远高于内存,否则的话,机器里就没有内存的存在。 由此看出,从远近来看:CPU <---> 寄存器 <---> 缓存 <---> 内存。