考查嵌入式C开发人员最好的十道题参考答案
详细参考答案
第1题: (b)
volatile字面意思是易于挥发的。这个关键字来描述一个变量时,意味着 给该变量赋值(写入)之后,马上再读取,写入的值与读取的值可能不一样,所以说它"容易挥发"的。
这是因为这个变量可能一个寄存器,直接与外部设备相连,你写入之后,该寄存器也有可能被外部设备的写操作所改变;或者,该变量被一个中断程序,或另一个进程
改变了.
volatile 不会被编译器优化影响,在longjump 后,它的值 是后面假定的变量值,b最后的值是5,所以5被打印出来.
setjmp : 设置非局部跳转 /* setjmp.h*/
Stores context information such as register values so that the lomgjmp function can return control to the statement following the one calling setjmp.Returns 0 when it is initially called.
Lonjjmp: 执行一个非局部跳转 /* setjmp.h*/
Transfers control to the statement where the call to setjmp (which initialized buf) was made. Execution continues at this point as if longjmp cannot return the value 0.A nonvolatile automatic variable might be changed by a call to longjmp.When you use setjmp and longjmp, the only automatic variables guaranteed to remain valid are those declared volatile.
Note: Test program without volatile qualifier (result may very)
更详细介绍,请参阅 C语言的setjmp和longjmp
第2题: (a)
结构题的成员在内存中的地址是按照他们定义的位置顺序依次增长的。如果一个结构体的指针被看成 它的第一个成员的指针,那么该指针的确指向第一个成员
第3题: (a)
此题目较难.
这个程序的非递归版本
int what ( int x , int n)
{
int val;
int product;
product =1;
val =x;
while(n>0)
{
if (n%2 == 1)
product = product*val; /*如果是奇数次幂, x(val)要先乘上一次,; 偶数次幂,最后返回时才会到这里乘以1*/
val = val* val;
n = n/2;
}
return product;
}/* 用二元复乘策略 */
算法描述
(while n>0)
{
if next most significant binary digit of n( power)&n
相关文档:
#1楼 得分:0回复于:2009-12-26 15:37:26
加密有很多种方法.同时C#也提供了很多加密方法.你需要加密和解密在加密算法上需要使用对称加密.我给你提供一个简单的算法.在保存的时候可以使用二进制的方式来保存到文件.
C# code
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography ......
1 fseek移动指针获取
#include <stdio.h>
#include <stdlib.h>
long filesize( FILE *fp )
{
long int save_pos;
long size_of_file;
/* Save the current position. */
save_pos = ftell( fp );
/* ......
在做windows驱动程序开发之前,首先要确定开发的语言。在常见的编程语言中,我们可以选择C、C++、汇编语言甚至Delphi。不过由于
微软提供的DDK开发环境所提供的文件和链接用的库只支持C和C++语言。所以一般都采用C或者C++。
使用C语言,是比较容易上手,因为很多人都是从学习C语言而学习程序开发的,而在驱动开发的 ......
非常基本关于C语言的问题,一个信息类(计算机,资讯工程,电子工程, 通信工程)专业的本科毕业生应该达到的水平。题目不难,全部都能快速地答完,当然也需要一定的知识储备。
对于大多数人,我们预期你可能答错 3) 4) 15)题,所以答错3道以内的,我们认为你很棒
答错5道题以内,我们认为你还不错(你还可能答 ......