叠拓C语言笔试题目(附答案)

更新时间:2023-06-22 09:23:35 阅读: 评论:0

Name:                                      Telephone No. : 
移动tv
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.检讨书800字
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)

本文发布于:2023-06-22 09:23:35,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1049623.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:证明   广告   来历   社区   登西
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图