高质量C++/C编程指南(附录B :C++/C试题)

林锐-高质量c/c++编程指南 返回主页高质量C++/C编程指南文件状态[ ] 草稿文件[√] 正式文件[ ] 更改正式文件 文件标识: 当前版本: 1.0作 者: 林锐 博士完成日期: 2001年7月24日版 本 历 史版本/状态 作者 参与者 起止日期 备注V 0.9草稿文件 林锐 2001-7-1至2001-7-18 林锐起草V 1.0正式文件 林锐 2001-7-18至2001-7-24 朱洪海审查V 0.9,林锐修正草 阅读详情
 

附录B :C++/C试题

       本试题仅用于考查C++/C程序员的基本编程技能。内容限于C++/C常用语法,不涉及数据结构、算法以及深奥的语法。考试成绩能反映出考生的编程质量以及对C++/C的理解程度,但不能反映考生的智力和软件开发能力。

       笔试时间90分钟。请考生认真答题,切勿轻视。

 

一、请填写BOOL , float, 指针变量 与“零值”比较的 if 语句。(10分)

提示:这里“零值”可以是0, 0.0 , FALSE或者“空指针”。例如 int 变量 n 与“零值”比较的 if 语句为:

    if ( n == 0 )

    if ( n != 0 )

以此类推。

 

请写出 BOOL  flag 与“零值”比较的 if 语句:

 

 

请写出 float  x 与“零值”比较的 if 语句:

 

 

 

请写出 char  *p 与“零值”比较的 if 语句:

 

 

 

二、以下为Windows NT下的32位C++程序,请计算sizeof的值(10分)

 

       char  str[] = “Hello” ;

       char   *p = str ;

int     n = 10;

请计算

sizeof (str ) =       

         

sizeof ( p ) =       

          

sizeof ( n ) =

void Func ( char str[100])

{

请计算

 sizeof( str ) =   

}

 

void *p = malloc( 100 );

请计算

sizeof ( p ) =

 

 

三、简答题(25分)

 

1、头文件中的 ifndef/define/endif 干什么用?

 

 

 

2、#include  <filename.h>   和  #include  “filename.h” 有什么区别?

 

 

 

3、const 有什么用途?(请至少说明两种)

 

 

 

4、在C++ 程序中调用被 C编译器编译后的函数,为什么要加 extern “C”声明?

 

 

 

 

5、请简述以下两个for循环的优缺点

 

// 第一个

for (i=0; i<N; i++)

{

if (condition)

    DoSomething();

else

    DoOtherthing();

}

// 第二个

if (condition)

{

for (i=0; i<N; i++)

    DoSomething();

}

else

{

    for (i=0; i<N; i++)

    DoOtherthing();

}

优点:

 

 

缺点:

 

 

 

优点:

 

 

缺点:

 

 

 

四、有关内存的思考题(20分)

 

void GetMemory(char *p)

{

p = (char *)malloc(100);

}

void Test(void)

{

char *str = NULL;

GetMemory(str);  

strcpy(str, "hello world");

printf(str);

}

 

请问运行Test函数会有什么样的结果?

答:

 

 

 

 

char *GetMemory(void)

{  

char p[] = "hello world";

return p;

}

void Test(void)

{

char *str = NULL;

str = GetMemory();   

printf(str);

}

 

请问运行Test函数会有什么样的结果?

答:

Void GetMemory2(char **p, int num)

{

*p = (char *)malloc(num);

}

void Test(void)

{

char *str = NULL;

GetMemory(&str, 100);

strcpy(str, "hello");  

printf(str);   

}

请问运行Test函数会有什么样的结果?

答:

 

 

 

 

 

void Test(void)

{

char *str = (char *) malloc(100);

    strcpy(str, “hello”);

    free(str);     

    if(str != NULL)

    {

      strcpy(str, “world”);

printf(str);

}

}

请问运行Test函数会有什么样的结果?

答:

 

 

 

 

 

 

五、编写strcpy函数(10分)

已知strcpy函数的原型是

       char *strcpy(char *strDest, const char *strSrc);

       其中strDest是目的字符串,strSrc是源字符串。

 

(1)不调用C++/C的字符串库函数,请编写函数 strcpy

 

 

 

 

 

 

 

(2)strcpy能把strSrc的内容复制到strDest,为什么还要char * 类型的返回值?

 

 

 

 

六、编写类String的构造函数、析构函数和赋值函数(25分)

已知类String的原型为:

    class String

    {

      public:

        String(const char *str = NULL);  // 普通构造函数

        String(const String &other);        // 拷贝构造函数

        ~ String(void);                        // 析构函数

        String & operate =(const String &other);    // 赋值函数

      private:

        char      *m_data;                // 用于保存字符串

    };

       请编写String的上述4个函数。

 

dex语法学习 学习和查看dex语法和了解smail语法的好文档。 立即下载

相关推荐

Smali语法学习与DEX文件详解

 什么是Smali语言 Smali代码是Android的Dalvik虚拟机的可执行文件DEX文件反汇编后的代码。所以Smali语言就是Dalvik的反汇编语言。 使用Apktool反编译apk 文件后,会在反编译工程目录下生成一个smali 文件夹,里面存放着所有反编译出的smali 文件,这些文件会根据程序包的层次结构生成相应的目录,程序中所有的类都会在相应的目录下生成独立的smali 文件。

dex文件格式学习

一.dex文件的生成 我们可以通过java文件来生成一个简单的dex文件 编译过程: 首先编写java代码如下: (1) 编译成 java class 文件 执行命令 : javac Hello.java 编译完成后 ,目录下生成 Hello.class 文件 (2) 编译成 dex 文件 dx --dex --out

Fly20141201. 的专栏 3940

《玩儿起来吧》MATLAB 实时图像处理系列(一二三四)

大家学了图像处理之后,是不是就想学以致用。而要用于生活中,最好的方式就是和摄像头搭配,实现实时图像处理。今天就给大家分享MATLAB实时图像处理的基础方法,希望能帮你快速入门。

HPC_ZY 1万+

DEX文件格式

1.DEX文件中使用的数据类型 u1,u2,u4,u8表示占某固定字节的无符号数 sleb128表示有符号的LEB128类型数据,uleb128表示无符号的LEB128,uleb128p1表示无符号的LEB128+1, 关于LEB128: LEB128是一种DEX文件中特有的用来存储最大32位数的数据类型,他的特点是字节数可以1-5可变。每个字节的第一位用来表示是否用到下个字...

weixin_30527323的博客 347

ENVI SARscape安装全攻略:从下载到汉化一步到位(附最新试用申请链接)

本文提供ENVI SARscape从下载安装到汉化的完整指南,特别针对InSAR(合成孔径雷达干涉测量)分析环境搭建。详细介绍了系统要求、分步安装流程、汉化优化方法及硬件加速配置,并分享数据处理验证和常见问题解决方案,帮助用户高效搭建遥感数据分析平台。

rnn9storyteller的博客 1408

将点云坐标转换成世界坐标的demo

将点云坐标转换成世界坐标的demo

howard789的博客 2206

Android关于Dex拆分(MultiDex)技术详解

一、前言关于Android中的分包技术,已经不是什么新的技术了,网上也有很多解析了,但是他们都是给了理论上的知道和原理解析,并没有详细的案例说明,所以这里我们就来详细讲解一下Android中dex拆分技术的解析。在讲解之前,我们还是先来看一下为什么有这个技术的出现?google为什么提供这样的技术。二、背景在开发应用时,随着业务规模发展到一定程度,不断地加入新功能、添加新的类库,代码在急剧的膨胀...

贵公子丶笔记 3183

PPPoe的抓包分析(详细)

PPPoe的报文结构 可以看出PPPoe的报文结构其实很简单,只不过是将PPPoe的报文塞到以太网的载荷中,而且它的头部字段也十分的简单,TLV就不说了,code字段表示了PPPoe不同的报文类型,比较常见的就是上面的五个报文了,PPPoe的报文类型其实还蛮多的。session ID主要的作用就是标识一段会话,因为使用PPPoe的最主要作用就是使得多台设备可以借助以太网多点接入多点访问的特点去和一台设备做上网认证请求,这样运营商一台认证设备就可以满足多个用户的认证请求,这和PPP相比起来好的不止一点。

qq_47529104的博客 7869

Android逆向笔记 —— DEX 文件格式解析

明天6.6号,六六大顺,提前祝各位小伙伴端午快乐!Class 文件格式详解Smali 语法解析——Hello WorldSmali —— 数学运算,条件判断,循环Smal...

文淑的博客 1008

私有云平台搭建——OpenStack

私有云平台搭建——OpenStack 搭建过程

2301_79739036的博客 3090

RuoYi-Cloud-Plus使用minio进行文件上传图片后无法预览解决_修改minio配置minio桶权限---SpringCloud工作笔记198

在文件管理的位置,发现刚刚上传的图片文件,会显示 预览图片失败 后来经过多方查看,发现是minio的配置的问题。可以看到首先登录RuoYi-Cloud-Plus系统然后,打开文件管理页面可以看到,当上传了图片文件以后。登录以后,选中左侧Buckets,可以看到有自己用的桶,找到以后点击打开。显示文件展示中,文件预览失败,那么这个时候,去修改minio的配置。可以看到,点击配置管理,这里我们启用的是minio对吧。默认是没有配置的这个时候,是允许下载,但不允许预览的.

添柴程序猿的专栏 5567

高质量C++编程指南 附录B:C++/C试题

一、请填写 BOOL , float, 指针变量 与“零值”比较的 if 语句。(10 分) 提示:这里“零值”可以是 0, 0.0 , FALSE 或者“空指针”。例如 int 变量 n 与“零值”比较的 if 语句为: if ( n == 0 ) if ( n != 0 ) 以此类推。 1、请写出boolflag与"零值"比较的if语句: 标准答...

请叫我皮皮虾的博客 348

【定位模块项目实战】gnss_localizer、lidar_localizer功能包解析

系列文章目录 提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加 TODO:写完再整理 文章目录系列文章目录前言一、1.2.3.4.二、1.2.3.4.三、1.2.3.4.四、1.2.3.4.总结参考资料 前言 认知有限,望大家多多包涵,有什么问题也希望能够与大家多交流,共同成长! 本文先对**【无人驾驶autoware项目实战】感知–定位模块**做个简单的介绍,具体内容后续再更,其他模块可以参考去我其他文章 提示:以下是本篇文章正文内容 一、 1. 2. 3. 4. . . 二、

qq_35635374的博客 1931

高质量C++/C编程指南 -- 附录B :C++/C试题

高质量C++/C编程指南 -- 附录B :C++/C试题及答案 全书参考:http://man.chinaunix.net/develop/c&c++/c/c.htm 附录B :C++/C试题  本试题仅用于考查C++/C程序员的基本编程技能。内容限于C++/C常用语法,不涉及数据结构、算法以及深奥的语法。考试成绩能反映出考生的编程质量以及对C++/C的理解程度,但不能反映考生的智力和软

Felix的专栏 807

[VT虚拟化驱动]正式启动VT

文章目录前言一、vmlaunch正式开始虚拟化二、使用步骤1.引入库2.读入数据总结 前言 本章开始真正实现一个最简单的VT框架,当然,只是能跑起来一个VT驱动了,没有并包括EPT,EPT后面再讲 提示:以下是本篇文章正文内容,下面案例可供参考 一、vmlaunch正式开始虚拟化 执行VMLAUNCH指令执行后,就正式进入虚拟化了,再该指令执行之前,得先保存Guest当前的环境,执行完VMLAUNCH后,要恢复Guest的环境,让Guest就像什么都没发生一样,所以需要保存和恢复Guest的各种寄存器的值

吾无法无天的博客 3661

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

高质量C++/C编程指南(附录B :C++/C试题) (转)

高质量C++/C编程指南(附录B :C++/C试题) (转)[@more@] 附录B :C++/C试题 本试题仅用于考查C++/C程序员的基本编程技能。内容限于C++/C常用语法,不涉及数据结构、算法以及深奥的语法。...

ciya3282的博客 250

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

高质量C++/C编程指南

高质量C++/C编程指南文件状态[  ] 草稿文件[√] 正式文件[  ] 更改正式文件文件标识:当前版本:1.0作    者:林锐博士完成日期:2001年7月24日版本历史版本/状态作者参与者起止日期备注V 0.9草稿文件林锐2001-7-1至2001-7-18林锐起草V 1.0正式文件林锐2001-7-18至2001-7-24朱洪海审查V 0.

QQ125864255的专栏 2577

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

高质量C++/C编程指南(经典)

看过之后感触很深!受有益良多!首先请做附录B的C++/C试题(不要看答案),考查自己的编程质量究竟如何。然后参照答案严格打分。 (1)如果你只得了几十分,请不要声张,也不要太难过。编程质量差往往是由于不良习惯造成的,与人的智力、能力没有多大关系,还是有药可救的。成绩越差,可以进步的空间就越大,中国不就是在落后中赶超发达资本主义国家吗?只要

dllbl的专栏 2040

高质量C/C++编程指南(PDF)下载介绍

高质量C/C++编程指南(PDF)下载介绍 去发现同类优质开源项目:https://gitcode.com/ 简介 本仓库提供了一本关于C/C++编程的指南,旨在帮助开发者提高编程质量和效率。本书详细介绍了文件结构、程序版式、命名规则、表达式与基本语句、常量、函数设计、内存管理、C++函数的高级特性、类的构造函数与析构函数、类的继承与组合以及其他编程经验等内容。 目录 以下是本书的详细目录: 前...

gitblog_06700的博客 853
上一篇: 高质量C++/C编程指南(第5章 常量)
下一篇: 高质量C++/C编程指南(附录C :C++/C试题的答案与评分标准)
icemanpro
博客等级 码龄25年 4粉丝 35原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值