一、 问答
1、实模式与保护模式。为什么要设计这两种模式?好处在什么地方?分别写出各自寻址的
过程。
2、请阅读以下一段程序,并给出答案。
class A
{
public:
A(){ doSth() }
virtual void doSth(){ printf(“I am A”);}
}
class B:public A
{
public:
virtual void doSth(){ printf(“I am B”);}
}
B b;
执行结果是什么?为什么?
3、在STL的应用中 map<int,int>这种key-value的应用很多,如果key的类型是GUID,该如
何处理?
4、一个内存变量a=5,有5个线程需要对其进行操作,其中3个对a进行加1操作,2个对a进
行减1操作,为了保证能够得到正常结果6,需要使用什么方法?(列出越多越好)
5、描述并比较以下对象:事件,信标,临界区,互斥对象。
6、cdecl、stdcall、fastcall是什么?哪种可以实现个数不定的入口参数,为什么?
二、 程序设计(以下题目请写出实现代码)
1、有一段文本,统计其中的单词数。例如:
As a technology , “HailStorm” is so new that it is still only known by its
code name.
注意:单词间的间隔不一定是一个空格
2、国际象棋有8×8格,每个格子可放一个棋子。皇后的规则是可以横、竖、斜移动。在一
个棋盘放置8个皇后,并使它们互相无法威胁到彼此。
3、输入二个64位的十进制数,计算相乘之后的乘积
已知strcpy函数的原型是:
char * strcpy(char * strDest,const char * strSrc);
1.不调用库函数,实现strcpy函数。
2.解释为什么要返回char *。
三
1. How do you code an infinite loop in C?
2. Volatile:
a) What does the keyword volatile mean? Give an example
b) Can a parameter be both const and volatile? Give an example
c) Can a pointer be volatile? Give an example
3. What are the values of a, b, and c after the following instructions:
int a=5, b=7, c;
c = a+++b;
4, What do the following declarations mean?
a) const int a;
b) int const a;
c) const int *a;
d) int * const a;
e) int const * a const;
5. Which of the following statements describe the use of the keyword
static?
a) Within the body of a function: A static variable maintains its value
between function revocations
b) Within a module: A static variable is accessible by all functions
within that module
c) Within a module: A static function can only be called by other
functions within that module
6. Embedded systems always require the user to manipulate bits in
registers or variables. Given an integer variable a, write two code fragments.
The first should set bit 5 of a. The second shnuld clear bit 5 of a. In both
cases, the remaining bits should be unmodified.
7. What does the following function return?
char foo(void)
{
unsigned int a = 6;
iht b = -20;
char c;
(a+b > 6) ? (c=1): (c=0);
return c;
}
8. What values are printed when the following C program is executed?
int i = 8;
void main(void)
(
9. What will be the output of the following C code?
main()
{
int k, num= 30;
k =(num > 5 ? (num <=10 ? 100:200): 500);
printf(“%d”, k);
}
10. What will the following C code do?
int *ptr;
ptr =(int *)Ox67a9;
*ptr = Oxaa55;
11. What will be the output of the follow C code?
#define product(x) (x*x)
main()
{
int i = 3, j, k;
j = product(i++);
k = product(++i);
printf(“%d %d”,j,k);
}
12. Simplify the following Boolean expression
!((i ==12) || (j > 15))
struct Node {
int value;
Node* next;
};
1.1 Get the value of the Nth node from last node in the linked list.
PARAM HEAD: the first element in the linked list:
PARAM n: the number of the node counted reversely
RETURN: the value of the node, or -1 if not exists
int GetValue(Node* HEAD, int n)
{
}
1.2 Delete a node WITHOUT using the HEAD pointer.
PARAM p: A pointer pointed to a node in the middle of the linked list.
RETURN: void
void Delete(Node* p)
{
}
1.3 Insert a new node before p WITHOUT using the HEAD pointer
PARAM p: A pointer pointed to a node in the middle of the linked list.
PARAM value: new Node value
RETURN: void
void Insert(Node* p, int value)
{
}
Question 2:
Please write a String class with following features:
四:
1. Default constructors with no parameters passed.
2. Constructor with parameter const char* sourceString passed.
3. Destructor.
4. Copy constructor.
5. Assignment operator.
6. Operator overloading operator+= which appends another String instance into current String instance.
7. A method returning length of the String.
8. A conversion operator which converts the current String instance into raw C-style string of type const char*.
五
1. Part of the signature of the String class is:
class String {
….
};
Other part of signature and implementation is completed by you.
2. Please make the implementation as simple as possible. Only help functions and classes from standard C&C++ may be used to aid your implementation.
3. If possible please suggest further improvement of the String class.
Question 3:
Given a link list, detect whether it’s circular using only one loop.
Tips: Below implementation is allowed
for( … )
{
…
}
The following implementations is NOT allowed
…
for( … )
{
…
for( … ) {…}
}
…
or
…
for( p = list->head, q = list->head; p != NULL && q != NULL; p = p->next )
{
…
}
…
for( … )
{
…
}
六
(1)
int Calc(unsigned int x)
{
int count=0;
while(x)
{
printf(“x=%in”,x);
count++;
x=x&(x-1);
}
return count;
}
问Calc(9999)的值是多少。
(2)检查错误
int CopyStringCount(const char* Str)
{
int nCount = 0;
char* pBuffer;
pBuffer = new char[_MAX_PATH];
strcpy(pBuffer,Str);
for(;*pBuffer!=’