龙灯舞Name: Telephone No. :
Date:
Instructions
Plea answer following questions in English, you can only u less than 60 minutes for this test
1. Preprocessor 10 points)
a) Plea define a Macro by using preprocess instruction #define in 16-bit machine, the constant is ud to indicate how many conds 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) Plea define a Macro, which is ud 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 <string.h>
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)
Plea 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)
Plea 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 ud to define a new structure which can replace the old structure.
You can also u preprocessor for the same things. But there must be difference between them, so plea 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 <iostream>
悦耳的英文
using namespace std;
class Ba
{
public:
virtual void f(float x){ cout << "Ba::f(float) " << x << endl; }
void g(float x){ cout << "Ba::g(float) " << x << endl; }
void h(float x){ cout << "Ba::h(float) " << x << endl; }
};
class Derived : public Ba
{
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;
Ba *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
Ba::g(float) 3.14
Derived::g(int) 3.14
Ba::h(float) 3.14
Derived::h(float) 3.14
2) #include <iostream>
using namespace std;
class A
{
public:
A(){ doSth(); }
virtual void doSth(){cout <<"I am A";}
};
class B:public A
{
public:
virtual void doSth(){ cout <<"I am B";}
};
void main(void)
{
B b;
}
Result: I am B
9. Write a function to convert a word from the "big-endian" format to the "little-endian" format. (15 points)