主页 > 小程序 > C程序设计语言合格是指什么考试?

C程序设计语言合格是指什么考试?

栏目: 作者: 时间:

一、C程序设计语言合格是指什么考试?

c语言有个全国计算机2级考试,分为笔试和上机考试2个部分,满分都是100分,这2个考试都达到60分以上,会有一个c语言二级证。c语言合格一般认为是这个考试吧

二、c程序设计语言书籍?

《C程序设计语言》是由C语言的设计者Dennis M. Ritchie和著名计算机科学家Brian W. Kernighan编写的一部介绍标准C语言及其程序设计方法的权威性经典著作。全面、系统地讲述了C语言的各个特性及程序设计的基本方法,包括基本概念、类型和表达式、控制流、函数与程序结构、指针与数组、结构、输入与输出、UNIX系统接口、标准库等内容。

三、c程序设计语言有几版?

C语言是一种程序编程语言,面向过程,介于高级语言和汇编语言之间。其历史可以追溯到贝尔实验室开发的B语言。1973年,丹尼斯·里奇-Dennis Ritchie 在其基础上开发了C语言,并在1976出版了《C程序设计语言》(简称K&R),确定C语言的基本语法。大致可以分为四个版本:1.C89-C90C89是美国标准协会ANSI制定的C语言标准。1990年,ISO批注了这个协议,成为了国际标准,称为C90。C90标准除了某些细节排版和C89不一样外,技术上两者无差别。2.C94-C95C94是ISO后续整理的C90的勘误版本,C95对C90做了微小扩充。值得一提的是,我国现行的C标准就是C94。3.C991999年,ISO发布C99版本。C99主要增加了部分库函数、增加了对复数的支持。4.C112011年,ISO发布了最新的C标准规范。目前世界上流行的还是C89\C90\C94\C95等版本,C99版本并不是所有的公司都支持

四、c语言程序设计语言有哪些?

实在太多了。一言难尽。 大至方向分为:Basic语言系列,C语言系列,汇编,…… 小分类:vb,delphi,java,QB,C,C++,C#,.NET,PASCAL…… 未完待补充。

五、c++是高级程序设计语言吗?

c++是属于高级程序设计语言,高级程序设计语言类别丰富,有良好的可移植性,在一种类型的机器上编写的程序不做很大的改动就能在别的机器上运行。

高级程序语言是指面向用户的、基本上独立于计算机种类和结构的语言。其最大的优点是:形式上接近于算术语言和自然语言,概念上接近于人们通常使用的概念。

六、c程序设计语言书属于什么类型?

C语言是一种面向过程的高级语言,在编程语言中没有中级语言,例如汇编语言是低级语言,汇编语言基于机器,是010101的助记符形式,其他大部分都是高级语言。

程序设计语言的发展经历了机器语言、汇编语言到高级语言的历程。其中机器语言和汇编语言都属于低级语言。

七、C++是不是高级程序设计语言?

c++是高级程序设计语言。

高级程序设计语言,亦称“算法语言”,简称“高级语言”。用易写和易懂的形式语言来编写程序的程序设计语言。可摆脱计算机指令系统和机器语言随机器不同的约束,并设计相应的编译程序(或称“编译器”),把适用于各种机器的高级语言编写的源程序转换为中央处理器能识别的目标代码。

八、c程序设计语言是机器语言吗?

c程序设计语言不是机器语言,是一种高级语言。

C语言是一种计算机程序设计语言。它既有高级语言的特点,又具有汇编语言的特点。它可以作为系统设计语言,编写工作系统应用程序,也可以作为应用程序设计语言,编写不依赖计算机硬件的应用程序。

九、c语言程序设计语言经历了哪些阶段?

程序设计语言的发展经历了从机器语言、汇编语言到高级语言三个阶段,其中c语言程序设计是高级阶段。。

第一阶段:机器语言

机器语言是由二进制 0、1 代码指令构成,不同的 CPU 具有不同的指令系统。机器语言程序难编写、难修改、难维护,需要用户直接对存储空间进行分配,编程效率极低。这种语言已经被渐渐淘汰了。

第二阶段:汇编语言

汇编语言指令是机器指令的符号化,与机器指令存在着直接的对应关系,所以汇编语言同样存在着难学难用、容易出错、维护困难等缺点。但是汇编语言也有自己的优点:可直接访问系统接口,汇编程序翻译成的机器语言程序的效率高。 从软件工程角度来看,只有在高级语言不能满足设计要求,或不具备支持某种特定功能的技术性能(如特殊的输入输出)时,汇编语言才被使用。

第三阶段高级语言

高级语言是面向用户的、基本上独立于计算机种类和结构的语言。其最大的优点是:形式上接近于算术语言和自然语言,概念上接近于人们通常使用的概念。高级语言的一个命令可以代替几条、几十条甚至几百条汇编语言的指令。因此,高级语言易学易用,通用性强,应用广泛。高级语言种类繁多,可以从应用特点和对客观系统的描述两个方面对其进一步分类。

十、c语言支持面向对象的程序设计语言?

1、引言

面向对象编程(OOP)并不是一种特定的语言或者工具,它只是一种设计方法、设计思想。它表现出来的三个最基本的特性就是封装、继承与多态。很多面向对象的编程语言已经包含这三个特性了,例如 Smalltalk、C++、Java。但是你也可以用几乎所有的编程语言来实现面向对象编程,例如 ANSI-C。要记住,面向对象是一种思想,一种方法,不要太拘泥于编程语言。

2、封装

封装就是把数据和方法打包到一个类里面。其实C语言编程者应该都已经接触过了,C 标准库

中的 fopen(), fclose(), fread(), fwrite()等函数的操作对象就是 FILE。数据内容就是 FILE,数据的读写操作就是 fread()、fwrite(),fopen() 类比于构造函数,fclose() 就是析构函数。这个看起来似乎很好理解,那下面我们实现一下基本的封装特性。#ifndef SHAPE_H#define SHAPE_H#include // Shape 的属性typedef struct {

int16_t x;

int16_t y;

} Shape;// Shape 的操作函数,接口函数void Shape_ctor(Shape * const me, int16_t x, int16_t y);void Shape_moveBy(Shape * const me, int16_t dx, int16_t dy);int16_t Shape_getX(Shape const * const me);int16_t Shape_getY(Shape const * const me);#endif /* SHAPE_H */

这是 Shape 类的声明,非常简单,很好理解。一般会把声明放到头文件里面 "Shape.h"。

来看下 Shape 类相关的定义,当然是在 "Shape.c" 里面。#include "shape.h"// 构造函数void Shape_ctor(Shape * const me, int16_t x, int16_t y) {

me->x = x;

me->y = y;

}void Shape_moveBy(Shape * const me, int16_t dx, int16_t dy) {

me->x += dx;

me->y += dy;

}// 获取属性值函数int16_t Shape_getX(Shape const * const me)

{ return me->x;

}int16_t Shape_getY(Shape const * const me)

{ return me->y;

}

再看下 main.c#include "shape.h" /* Shape class interface */#include /* for printf() */int main() {

Shape s1, s2; /* multiple instances of Shape */

Shape_ctor(&s1, 0, 1);

Shape_ctor(&s2, -1, 2); printf("Shape s1(x=%d,y=%d)\n", Shape_getX(&s1), Shape_getY(&s1)); printf("Shape s2(x=%d,y=%d)\n", Shape_getX(&s2), Shape_getY(&s2));

Shape_moveBy(&s1, 2, -4);

Shape_moveBy(&s2, 1, -2); printf("Shape s1(x=%d,y=%d)\n", Shape_getX(&s1), Shape_getY(&s1)); printf("Shape s2(x=%d,y=%d)\n", Shape_getX(&s2), Shape_getY(&s2)); return 0;

}

编译之后,看看执行结果:Shape s1(x=0,y=1)

Shape s2(x=-1,y=2)

Shape s1(x=2,y=-3)

Shape s2(x=0,y=0)

整个例子,非常简单,非常好理解。以后写代码时候,要多去想想标准库的文件IO操作,这样也有意识的去培养面向对象编程的思维。

3、继承

继承就是基于现有的一个类去定义一个新类,这样有助于重用代码,更好的组织代码。在 C 语言里面,去实现单继承也非常简单,只要把基类放到继承类的第一个数据成员的位置就行了。

例如,我们现在要创建一个 Rectangle 类,我们只要继承 Shape 类已经存在的属性和操作,再添加不同于 Shape 的属性和操作到 Rectangle 中。

下面是 Rectangle 的声明与定义:#ifndef RECT_H#define RECT_H#include "shape.h" // 基类接口// 矩形的属性typedef struct {

Shape super; // 继承 Shape

// 自己的属性

uint16_t width; uint16_t height;

} Rectangle;// 构造函数void Rectangle_ctor(Rectangle * const me, int16_t x, int16_t y, uint16_t width, uint16_t height);#endif /* RECT_H */#include "rect.h"// 构造函数void Rectangle_ctor(Rectangle * const me, int16_t x, int16_t y, uint16_t width, uint16_t height){ /* first call superclass’ ctor */

Shape_ctor(&me->super, x, y); /* next, you initialize the attributes added by this subclass... */

me->width = width;

me->height = height;

}

我们来看一下 Rectangle 的继承关系和内存布局

AAffA0nNPuCLAAAAAElFTkSuQmCC

内存布局

因为有这样的内存布局,所以你可以很安全的传一个指向 Rectangle 对象的指针到一个期望传入 Shape 对象的指针的函数中,就是一个函数的参数是 "Shape *",你可以传入 “Rectangle *”,并且这是非常安全的。这样的话,基类的所有属性和方法都可以被继承类继承!#include "rect.h" #include int main() {

Rectangle r1, r2; // 实例化对象

Rectangle_ctor(&r1, 0, 2, 10, 15);

Rectangle_ctor(&r2, -1, 3, 5, 8); printf("Rect r1(x=%d,y=%d,width=%d,height=%d)\n",

Shape_getX(&r1.super), Shape_getY(&r1.super),

r1.width, r1.height); printf("Rect r2(x=%d,y=%d,width=%d,height=%d)\n",

Shape_getX(&r2.super), Shape_getY(&r2.super),

r2.width, r2.height); // 注意,这里有两种方式,一是强转类型,二是直接使用成员地址

Shape_moveBy((Shape *)&r1, -2, 3);

Shape_moveBy(&r2.super, 2, -1); printf("Rect r1(x=%d,y=%d,width=%d,height=%d)\n",

Shape_getX(&r1.super), Shape_getY(&r1.super),

r1.width, r1.height); printf("Rect r2(x=%d,y=%d,width=%d,height=%d)\n",

Shape_getX(&r2.super), Shape_getY(&r2.super),

r2.width, r2.height); return 0;

}

输出结果:Rect r1(x=0,y=2,width=10,height=15)

Rect r2(x=-1,y=3,width=5,height=8)

Rect r1(x=-2,y=5,width=10,height=15)

Rect r2(x=1,y=2,width=5,height=8)

4、多态

C++ 语言实现多态就是使用虚函数。在 C 语言里面,也可以实现多态。

现在,我们又要增加一个圆形,并且在 Shape 要扩展功能,我们要增加 area() 和 draw() 函数。但是 Shape 相当于抽象类,不知道怎么去计算自己的面积,更不知道怎么去画出来自己。而且,矩形和圆形的面积计算方式和几何图像也是不一样的。

下面让我们重新声明一下 Shape 类#ifndef SHAPE_H#define SHAPE_H#include struct ShapeVtbl;// Shape 的属性typedef struct {

struct ShapeVtbl const *vptr;

int16_t x;

int16_t y;

} Shape;// Shape 的虚表struct ShapeVtbl {

uint32_t (*area)(Shape const * const me); void (*draw)(Shape const * const me);

};// Shape 的操作函数,接口函数void Shape_ctor(Shape * const me, int16_t x, int16_t y);void Shape_moveBy(Shape * const me, int16_t dx, int16_t dy);int16_t Shape_getX(Shape const * const me);int16_t Shape_getY(Shape const * const me);static inline uint32_t Shape_area(Shape const * const me) { return (*me->vptr->area)(me);

}static inline void Shape_draw(Shape const * const me){

(*me->vptr->draw)(me);

}Shape const *largestShape(Shape const *shapes[], uint32_t nShapes);void drawAllShapes(Shape const *shapes[], uint32_t nShapes);#endif /* SHAPE_H */

看下加上虚函数之后的类关系图

AAffA0nNPuCLAAAAAElFTkSuQmCC

虚函数类图

4.1 虚表和虚指针

虚表(Virtual Table)是这个类所有虚函数的函数指针的集合。

虚指针(Virtual Pointer)是一个指向虚表的指针。这个虚指针必须存在于每个对象实例中,会被所有子类继承。

在《Inside The C++ Object Model》的第一章内容中,有这些介绍。

4.2 在构造函数中设置vptr

在每一个对象实例中,vptr 必须被初始化指向其 vtbl。最好的初始化位置就是在类的构造函数中。事实上,在构造函数中,C++ 编译器隐式的创建了一个初始化的vptr。在 C 语言里面, 我们必须显示的初始化vptr。

下面就展示一下,在 Shape 的构造函数里面,如何去初始化这个 vptr。#include "shape.h"#include // Shape 的虚函数static uint32_t Shape_area_(Shape const * const me);static void Shape_draw_(Shape const * const me);// 构造函数void Shape_ctor(Shape * const me, int16_t x, int16_t y) { // Shape 类的虚表

static struct ShapeVtbl const vtbl =

{

&Shape_area_,

&Shape_draw_

};

me->vptr = &vtbl;

me->x = x;

me->y = y;

}void Shape_moveBy(Shape * const me, int16_t dx, int16_t dy){

me->x += dx;

me->y += dy;

}int16_t Shape_getX(Shape const * const me)

{ return me->x;

}int16_t Shape_getY(Shape const * const me)

{ return me->y;

}// Shape 类的虚函数实现static uint32_t Shape_area_(Shape const * const me) {

assert(0); // 类似纯虚函数

return 0U; // 避免警告}static void Shape_draw_(Shape const * const me) {

assert(0); // 纯虚函数不能被调用}Shape const *largestShape(Shape const *shapes[], uint32_t nShapes) {

Shape const *s = (Shape *)0; uint32_t max = 0U; uint32_t i; for (i = 0U; i

{ uint32_t area = Shape_area(shapes[i]);// 虚函数调用

if (area > max)

{

max = area;

s = shapes[i];

}

} return s;

}void drawAllShapes(Shape const *shapes[], uint32_t nShapes) { uint32_t i; for (i = 0U; i

{

Shape_draw(shapes[i]); // 虚函数调用

}

}

注释比较清晰,这里不再多做解释。

4.3 继承 vtbl 和 重载 vptr

上面已经提到过,基类包含 vptr,子类会自动继承。但是,vptr 需要被子类的虚表重新赋值。并且,这也必须发生在子类的构造函数中。下面是 Rectangle 的构造函数。#include "rect.h" #include // Rectangle 虚函数static uint32_t Rectangle_area_(Shape const * const me);static void Rectangle_draw_(Shape const * const me);// 构造函数void Rectangle_ctor(Rectangle * const me, int16_t x, int16_t y, uint16_t width, uint16_t height){ static struct ShapeVtbl const vtbl =

{

&Rectangle_area_,

&Rectangle_draw_

};

Shape_ctor(&me->super, x, y); // 调用基类的构造函数

me->super.vptr = &vtbl; // 重载 vptr

me->width = width;

me->height = height;

}// Rectangle's 虚函数实现static uint32_t Rectangle_area_(Shape const * const me) {

Rectangle const * const me_ = (Rectangle const *)me; //显示的转换

return (uint32_t)me_->width * (uint32_t)me_->height;

}static void Rectangle_draw_(Shape const * const me) {

Rectangle const * const me_ = (Rectangle const *)me; //显示的转换

printf("Rectangle_draw_(x=%d,y=%d,width=%d,height=%d)\n",

Shape_getX(me), Shape_getY(me), me_->width, me_->height);

}

4.4 虚函数调用

有了前面虚表(Virtual Tables)和虚指针(Virtual Pointers)的基础实现,虚拟调用(后期绑定)就可以用下面代码实现了。uint32_t Shape_area(Shape const * const me)

{ return (*me->vptr->area)(me);

}

这个函数可以放到.c文件里面,但是会带来一个缺点就是每个虚拟调用都有额外的调用开销。为了避免这个缺点,如果编译器支持内联函数(C99)。我们可以把定义放到头文件里面,类似下面:static inline uint32_t Shape_area(Shape const * const me) { return (*me->vptr->area)(me);

}

如果是老一点的编译器(C89),我们可以用宏函数来实现,类似下面这样:#define Shape_area(me_) ((*(me_)->vptr->area)((me_)))

看一下例子中的调用机制:

AAffA0nNPuCLAAAAAElFTkSuQmCC

虚拟调用机制

4.5 main.c#include "rect.h" #include "circle.h" #include int main() {

Rectangle r1, r2;

Circle c1, c2;

Shape const *shapes[] =

{

&c1.super,

&r2.super,

&c2.super,

&r1.super

};

Shape const *s; // 实例化矩形对象

Rectangle_ctor(&r1, 0, 2, 10, 15);

Rectangle_ctor(&r2, -1, 3, 5, 8); // 实例化圆形对象

Circle_ctor(&c1, 1, -2, 12);

Circle_ctor(&c2, 1, -3, 6);

s = largestShape(shapes, sizeof(shapes)/sizeof(shapes[0])); printf("largetsShape s(x=%d,y=%d)\n", Shape_getX(s), Shape_getY(s));

drawAllShapes(shapes, sizeof(shapes)/sizeof(shapes[0])); return 0;

}

输出结果:largetsShape s(x=1,y=-2)

Circle_draw_(x=1,y=-2,rad=12)

Rectangle_draw_(x=-1,y=3,width=5,height=8)

Circle_draw_(x=1,y=-3,rad=6)

Rectangle_draw_(x=0,y=2,width=10,height=15)

5、总结

还是那句话,面向对象编程是一种方法,并不局限于某一种编程语言。用 C 语言实现封装、单继承,理解和实现起来比较简单,多态反而会稍微复杂一点,如果打算广泛的使用多态,还是推荐转到 C++ 语言上,毕竟这层复杂性被这个语言给你封装了,你只需要简单的使用就行了。但并不代表,C 语言实现不了多态这个特性。