叠拓测试笔试题
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

相关内容

热门资讯

耸人听闻的反义词 耸人听闻的反义词有:不偏不倚,本来面目,耸人听闻[sǒng rén tīng wén]的意思:耸:引...
朴素的反义词是什么 朴素的反义词是什么朴素的反义词是什么1  朴素相关的反义词:  奢华华丽艳丽  中文解释:  [si...
个人主义的反义词 个人主义的反义词有:集体主义,个人主义[gè rén zhǔ yì]的意思:个人本身的利益应该高于一...
身操井臼的反义词 身操井臼的反义词有:呼奴使婢,身操井臼[shēn cāo jǐng jiù]的意思:语本《后汉书 冯...
蝎蝎螫螫的反义词 蝎蝎螫螫的反义词有:干脆利落,蝎蝎螫螫[xiē xiē zhē zhē]的意思:形容人婆婆妈妈,在小...
奔走相告的反义词 奔走相告的反义词有:呆若木鸡,面如土色,奔走相告[bēn zǒu xiāng gào]的意思:奔;走...
稀疏的反义词是什么   一、【反义词】  稠密、茂密、茂盛、密集、繁茂、浓密、细密  二、【基本解释】  ◎ 稀疏 xī...
刻不容缓的反义词 刻不容缓的反义词有:悠闲自得,绰绰有余,刻不容缓[kè bù róng huǎn]的意思:刻:片刻;...
从容就义的反义词 从容就义的反义词有:贪生怕死,从容就义[cóng róng jiù yì]的意思:从容:不慌不忙;镇...
忧心如薰的近义词 忧心如薰的近义词有:忧心如焚,忧心如薰[yōu xīn rú xūn]的意思:薰:同“熏”。忧虑的心...
梁孟相敬的近义词 梁孟相敬的近义词有:举案齐眉,梁孟相敬[liáng mèng xiāng jìn]的意思:原指东汉时...
养威蓄锐的近义词 养威蓄锐的近义词有:养锐蓄威,蓄锐养威,养威蓄锐[yǎng wēi xù ruì]的意思:培植威力,...
心粗胆壮的近义词 心粗胆壮的近义词有:心粗胆大,心粗胆壮[xīn cū dǎn zhuàng]的意思:粗:粗疏,粗略。...
误解的近义词 误解的近义词  误解是指认识与对象的不一致,即行为人对民事行为的内容或其他有关情况产生认识上的错误,...
万籁俱寂的近义词 万籁俱寂的近义词有:万籁俱静,万籁无声,万马齐喑,夜深人静,寂然无声,阒寂无声,阗寂无声,鸦雀无声,...
郑人买履的近义词 郑人买履的近义词有:死搬教条,生搬硬套,郑人买履[zhèng rén mǎi lǚ]的意思:履:鞋。...
识涂老马的近义词 识涂老马的近义词有:识途老马,识涂老马[shí tú lǎo mǎ]的意思:见“识途老马”。出自:清...
食甘寝安的近义词 食甘寝安的近义词有:食甘寝宁,食甘寝安[shí gān qǐn ān]的意思:见“食甘寝宁”。出自:...
诗朋酒友的近义词 诗朋酒友的近义词有:诗朋酒侣,诗朋酒侪,诗朋酒友[shī péng jiǔ yǒu]的意思:作诗饮酒...
慢慢近义词是什么详解 慢慢近义词是什么详解  中国文化博大精深、源远流长,诗词句子故事更是多不胜数。下面是小编为您带来的慢...