搜索
您的当前位置:首页正文

Introduction of C language

来源:二三娱乐

1 Why C?

C language gives programmer great control
e.g. 精确到内存单元, 可循环到内存溢出(python 1000次左右即终止)
Produce faster code
C编译的速度优势是明显的
Widely used
有足够多的support library 和 community support, 同样在industry 和 science上都有足够多的应用,即:从功利的角度和踩坑的角度,这门先祖语言都有足够的优势

2 Brief History

C and UNIX share a complex history
C was originally designed for an implement on UNIX on a PDP-11 computer
Dennis Ritchie was the author of C(1971)
In 1973, UNIX was rewritten in C.
B is the predecessor of C, but there is no A.
In 1983, American National Standard Institute(ANSI) clean up and standardise the language.
In 1988, ANSI C published.
Till now, C is the main language for operation systems and compliers.

3 C language basic knowledge

1 basic structure of C

 

include files

可以是库函数,也可以是自定义库函数

define var value

全局变量,实际上也是只在本file中使用,不是整个project
file间的变量交流,还是靠函数的传参大法
C function,这个基本上学过编程的人有有所了解,关于形参、实参、返回值等知识略。
int main(argc, argv){}
入口函数,如果以int作为入口函数类型,那么一定有返回值,0代表successful executing, 1代表error occurs.
如果用 void,实际上是默认返回0的int的简写。
入口函数参数:
argc: #parameters, parameter指命令行传入的参数
argv: actual parameters, refer 一个 stackoverflow的例子,很简明。

image.png
注意: C project只有一个入口,多个入口会报错。
Tips: 什么时候是地址什么时候是指针,这是C语言初学者最应该明确也是最长犯错的点。
image.png
(I put it on Code Wall)[
compile:
main.C -> object file main.o -> executable file main.out
Top