叠拓测试笔试题
admin
2024-02-18 07:49:12
0

叠拓测试笔试题

下面是为您介绍的关于叠拓测试笔试题,请您对此进行参考:

Instructions
Please answer following questions in English, you can only use less than 60 minutes for this test

1. Preprocessor 10 points)
a) Please define a Macro by using preprocess instruction #define in 16-bit machine, the constant is used to indicate how many seconds in one year. (To ignore the leap year)

#define SEC_PER_YEAR (365*24*60*60UL)
(Note: If you define it to be (365*24*60*60)UL, you maybe find that it does not compile well.)


b) Please define a Macro, which is used to compare two parameters and return the smaller parameter.

#define MIN(a, b) ((a)<=(b)?(a):(b))


2. What is the problem of the below code (5 points)
#include
char* Func( void )
{
char p[10];
strcpy( p, "111" );
return p;
}

This function can not return the string of “111”.

3. Data declarations (10 points)
Please define a variable according to the below requirement, for example
Requirement: An integer
Answer: int a;

a) A pointer to an integer (1 point)
int *a;

b) A pointer to a pointer to an integer (1 point)
int **a;

c) An array of 10 integers (1 point)
int a[10];

d) An array of 10 pointers to integers (1 point)
int *a[10];


e) A pointer to an array of 10 integers (2 points)
int (*a)[10];

f) A pointer to a function that takes an integer as an argument and returns an integer (2 points)
int (*a)(int)

g) An array of ten pointers to functions that take an integer argument and return an integer (2 points)
int (*a[10])(int)

4. What’s the output of the function and why? (6 points)
void foo(void)
{
unsigned int a = 6;
int b = -20;
(a+b > 6) ? puts("> 6") : puts("<= 6");
}

Result:“>6”
Reason: When a variable of integer operates with a variable of unsigned integer, the integer will be automatically converted to unsigned integer, so the “-20” will be converted to be a large unsigned integer.


5. Const (9 points)
In the following codes, there are some “const”, what is meaning of each them?

a) const char *pa;
The content of pa is read-only.

b) char * const pc = &ca;
The address of pc is read-only.


c) const char * const pd =

&cb;
Both the address and content of pd are read-only.

6. Accessing fixed memory locations (10 points)
Please make out a few lines of C codes for accessing a fixed memory location. Requirement is to write an int variable 0xaa55 into the fixed address 0x67a9.

int *p;
p = (int *)0x67a9;
*p = 0xaa55;



7. Typedef (10 points)
Typedef is used to define a new structure which can replace the old structure.
You can also use preprocessor for the same things. But there must be difference between them, so please think of the below code, and answer what is the difference?

#define dPS struct s *
typedef struct s * tPS;


I will declare two object variables for them, such as:
dPS test1, test2;
tPS test3, test4;

You will understand what’s the differences.
1. test1 is a pointer object of struct s, but test2 is not, it is object of struct s.
2. both test3 and test4 are pointer object of struct s.


8. What’s the output of the code? (10 points)
1) #include
using namespace std;

class Base
{
public:
virtual void f(float x){ cout << "Base::f(float) " << x << endl; }
void g(float x){ cout << "Base::g(float) " << x << endl; }
void h(float x){ cout << "Base::h(float) " << x << endl; }
};

class Derived : public Base
{
public:
virtual void f(float x){ cout << "Derived::f(float) " << x << endl; }
void g(int x){ cout << "Derived::g(int) " << x << endl; }
void h(float x){ cout << "Derived::h(float) " << x << endl; }
};

void main(void)
{
Derived d;
Base *pb = &d;
Derived *pd = &d;
pb->f(3.14f);
pd->f(3.14f);
pb->g(3.14f);
pd->g(3.14f);
pb->h(3.14f);
pd->h(3.14f);
}

Result:
Derived::f(float) 3.14
Derived::f(float) 3.14
Base::g(float) 3.14
Derived::g(int) 3.14
Base::h(float) 3.14
Derived::h(float) 3.14

相关内容

热门资讯

故乡的小河初中优秀作文(经典... 故乡的小河初中优秀作文 篇一:清澈的小河故乡的小河,是我童年最美好的回忆之一。每当我回忆起那清澈的水...
爱上篮球作文【精简5篇】 爱上篮球作文 篇一篮球是一项非常受欢迎的运动,它不仅能够锻炼身体,还能培养团队合作和竞争意识。我也是...
在黑夜中学会等待初一作文30... 在黑夜中学会等待初一作文300字 篇一黑夜中的等待初一,对于每个学生来说都是一个重要的时刻。对于我来...
我的偶像作文(优选6篇) 我的偶像作文 篇一我所敬仰的偶像是我的父亲每个人心中都有一个自己所敬仰的偶像,而在我心中,我最尊敬的...
初一满分作文(精彩6篇) 初一满分作文 篇一我的初一生活初一,对于每个初中生来说,是一个全新的开始。我也不例外,迎来了我人生中...
初一新生必读书目推荐(优选4... 初一新生必读书目推荐 篇一作为初一新生,进入中学是一个全新的起点。在这个阶段,通过阅读可以帮助学生拓...
我与语文作文600字初一(最... 我与语文作文600字初一 篇一初中一年级的语文课程,对于我来说是全新的开始。刚开始上课时,我感到有些...
初一作文我的新老师800字(... 初一作文我的新老师800字 篇一我的新老师新学期开始了,我迎来了一位新的班主任老师,她叫李老师。李老...
初一作文开学第一天(实用3篇... 初一作文开学第一天 篇一开学第一天,我怀着忐忑不安的心情踏入了初中校园。新的环境、新的老师、新的同学...
中山詹园初中作文(精简5篇) 中山詹园初中作文 篇一:我与音乐的故事音乐是我的生命,它给了我无穷的力量和激情。每当我听到动听的旋律...
初中生的《变形计》观后感作文... 初中生的《变形计》观后感作文 篇一《变形计》是一部引人深思的电视剧,它以幽默风趣的方式揭示了人性的复...
温暖人间初中作文600字【最... 温暖人间初中作文600字 篇一 温暖人间初中作文600字 篇二温暖人间初中作文600字 篇三温暖人间...
为什么会打嗝初一作文(优选3... 为什么会打嗝初一作文 篇一打嗝是一种常见的生理现象,几乎每个人都会经历。无论是小孩还是成人,都会在某...
七年级优秀作文【优选6篇】 七年级优秀作文 篇一勇敢面对挑战在我们的成长道路上,面对各种各样的挑战是不可避免的。然而,如何勇敢地...
初中作文春节南游记(通用6篇... 初中作文春节南游记 篇一初中作文春节南游记今年的春节,我的家人决定去南方旅游,感受一下不一样的春节氛...
初一作文(精彩6篇) 初一作文 篇一:我心中的梦想梦想是每个人心中最美丽的花朵,它给予我们力量和希望。在我心中,我的梦想是...
七年级作文新朋友通用11篇 七年级作文新朋友 第一篇朋友,是你伤心的时候来安慰你;朋友,是你失落时来鼓励你;朋友,是你生病时来照...
毕业的我们初中作文【精简3篇... 毕业的我们初中作文 篇一初中三年的时光如同一阵风,转眼间就要毕业了。回首这三年的学习生活,我觉得自己...
乐在其中初中作文(优质6篇) 乐在其中初中作文 篇一我的乐趣每个人都有自己喜欢的事物和乐趣所在。对我来说,写作是我最喜欢的活动之一...
诚信初中作文600字(精选6... 诚信初中作文600字 篇一:诚信的重要性诚信是人们在日常生活中应该遵守的基本品质,也是社会发展的重要...