现在的位置: 首页 > 综合 > 正文

微软2013暑假实习生笔试题解析

2018年04月23日 ⁄ 综合 ⁄ 共 6111字 ⁄ 字号 评论关闭

所有题目为不定项选择

1. Which of the following calling convention(s) support(s) support variable-length parameter(e.g.printf)?(3 Points)

A. cdecl
B. stdcall
C. pascal
D. Fastcall
答案:A
解析:此题是对几种函数的调用方式的考查。
  __cdecl 是C Declaration的缩写(declaration,声明),表示C语言默认的函数调用方法:所有参数从右到左依次入栈,这些参数由调用者清除,称为手动清栈。被调用函数不会要求调用者传递多少参数,调用者传递过多或者过少的参数,甚至完全不同的参数都不会产生编译阶段的错误。
  stdcall 是Standard Call的缩写,是C++的标准调用方式:所有参数从右到左依次入栈,如果是调用类成员的话,最后一个入栈的是this指针。这些堆栈中的参数由被调用的函数在返回后清除,使用的指令是 retnX,X表示参数占用的字节数,CPU在ret之后自动弹出X个字节的堆栈空间。称为自动清栈。函数在编译的时候就必须确定参数个数,并且调用者必须严格的控制参数的生成,不能多,不能少,否则返回后会出错。
  PASCAL 是Pascal语言的函数调用方式,也可以在C/C++中使用,参数压栈顺序与前两者相反。返回时的清栈方式与_stdcall相同。
  _fastcall是编译器指定的快速调用方式。由于大多数的函数参数个数很少,使用堆栈传递比较费时。因此_fastcall通常规定将前两个(或若干个)参数由寄存器传递,其余参数还是通过堆栈传递。不同编译器编译的程序规定的寄存器不同。返回方式和_stdcall相当。

2. What's the output of the following code?(3 Points)
class A
{
public:
virtual void f()
{
    cout<<"A::f()"<<endl;
}
void f() const
{
    cout<<"A::f() const"<<endl;
}
};
class B: public A
{
public:
void f()
{
    cout<<"B::f()"<<endl;
}
void f() const
{
    cout<<"B::f() const"<<endl;
}
};
void g(const A* a)
{
    a->f();
}
int main()
{
  A* a = new B();
  a->f();
  g(a);
  delete a ;
}
A. B::f()B::f()const
B. B::f()A::f()const
C. A::f()B::f()const
D. A::f()A::f()const
答案:B
解析:此题考的是继承中的多态问题,即虚函数覆盖的问题,对于直接调用a->f(),是会调用B类的f()函数。但是如果传到A中,由于const函数没被覆盖,因此会调用A的const f()函数,因此要选B。

3. What is the difference between a linked list and an array?(3 Points)
A. Search complexity when both are sorted
B. Dynamically add/remove
C. Random access efficiency
D. Data storage type
答案:ABC
解析:考查数组和链表的差别。

4. About the Thread and Process in Windows, which description(s) is(are) correct:(3 Points)

A. One application in OS must have one Process, but not a necessary to have one Thread
B. The Process could have its own Stack but the thread only could share the Stack of its parent Process
C. Thread must belongs to a Process
D. Thread could change its belonging Process

答案:C
解析:一个application至少有一个线程和一个进程。线程也有自己的栈空间。线程不能改变其从属进程。

5. What is the output of the following code?(3 Points)
{
  int x = 10 ;
  int y = 10 ;
  x = x++ ;
  y = ++y ;
  printf("%d, %d\n",x,y);
}
A. 10, 10
B. 10, 11
C. 11, 10
D. 11, 11
答案:B or D
解析:此题有一点疑惑,编译器不同,答案不同。理论上讲,x++后,x的值变为11,但其返回值仍是10,++y毫无疑问是11.所以理论上面应该是10,11.但在vs上面测试答案是11,11.

6. For the following Java or C# code(3 Points)
int [][] myArray3 =
new int[3][]{
new int[3]{5,6,2},
new int[5]{6,9,7,8,3},
new int[2]{3,2}};

What will myArray3[2][2] returns?
A. 9
B. 2
C. 6
D. Overflow
答案:D
解析:数组溢出

7. Please choose the right statement about const usage:(3 Points)
A. const int a; //const integer
B. int const a; //const integer
C. int const *a; //a pointer which point to const integer
D. const int *a; //a const pointer which point to integer
E. int const *a; // a const pointer which point to integer
答案:ABC
解析:const的语法。参照关于const

8. Given the following code:(3 Points)
#include <iostream>
class A{
public:
long a;
};
class B : public A
{
public:
    long b;
};
void seta(A* data, int idx)
{
    data[idx].a = 2;
}
int _tmain(int argc, _TCHAR *argv[])
{
B data[4];
  for(int i=0; i<4; ++i)
  {
         data[i].a = 1;
         data[i].b = 1;
         seta(data, i);
  }

  for(int i=0; i<4; ++i)
  {
         std::cout<<data[i].a<<data[i].b;
  }
  return 0;
}
What is the correct result?
A. 11111111
B. 12121212
C. 11112222
D. 21212121
【此题答案貌似应该是 22221111】

解析:注意A的大小是4字节,B的大小是8字节,B data[4]总共有32字节,在调用seta函数的时候,由于使用的是A的指针,因此每次步进只有4字节。因此只把前4个long值置为了2。

9. 1 of 1000 bottles of water is poisoned which will kill a rat in 1 week if the rat drunk any amout of the water. Given the bottles of water have no visual difference, how many rats are needed at least to find the poisoned one in 1 week?(5 Points)
A. 9
B. 10
C. 32
D. None of the above
答案:B
解析:2^10 = 1024.二进制编码问题。

10. Which of the following statement(s) equal(s) value 1 in C programming language?(5
Points)
A. the return value of main function if program ends normally
B. return (7&1)
C. char *str="microsoft"; return str=="microsoft"
D. return "microsoft"=="microsoft"
E. None of the above
答案:BCD

11. If you computed 32 bit signed integers F and G from 32 bit signed X using F = X / 2 and G = (X>>1), and you found F!=G, this implies that(5 Points)
A. There is a compiler error
B. X is odd
C. X is negative
D. F - G = 1
E. G - F = 1
答案:C
解析:负数右移高位补符号位

12. How many rectangles you can find from 3*4 grid?(5 Points)
A. 18
B. 20
C. 40
D. 60
E. None of above is correct
答案:D
解析:横向的点数有5,纵向的有4,因此是排列组合的从5个中选2个,乘以从4个中选两个,即10*6 = 60

13. One line can split a surface to 2 part, 2 line can split a surface to 4 part. Given 100 lines, no two parallel lines, no tree lines join at same point, how many parts can 100 line split?(5 Points)
A. 5051
B. 5053
C. 5510
D. 5511
答案:A
解析:找规律。f(n) = n + f(n-1),f(1)=2.所以f(100) = 5051.

14. Which of the following sorting algorithm(s) is(are) stable sorting?(5 Points)
A. bubble sort
B. quick sort
C. heap sort
D. merge sort
E. Selection sort
答案:AD
解析:稳定的排序有:冒泡排序、鸡尾酒排序、插入排序、合并排序、桶排序、基数排序、二叉树排序、图书馆排序;
不稳定的排序有:选择排序、希尔排序、堆排序、快速排序。

15. Model-View-Controller(MVC) is an architectural pattern that frequently used in web applications. Which of the following statement(s) is(are) correct:(5 Points)
A. Models often represent data and the business logics needed to manipulate the data in the application
B. A view is a (visual) representation of its model. It renders the model into a form suitable for interaction, typically a user interface element
C. A controller is the link between a user and the system. It accepts input from the user and instructs the model and a view to perform actions based on that input
D. The common practice of MVC in web applications is, the model receives GET or POST input from user and decides what to do with it, handing over to controller and which hand control to views(HTML-generating components)
E. None of the above
答案:AB

16. we can recover the binary tree if given the output of(5 Points)
A. Preorder traversal and inorder traversal
B. Preorder traversal and postorder traversal
C. Inorder traversal and postorder traversal
D. Postorder traversal
答案:AC
解析:要确定一棵二叉树,一定要知道中序遍历。再加上前序或后序。

17. Given a string with n characters, suppose all the characters are different from each other, how many different substrings do we have?(5 Points)
A. n+1
B. n^2
C. n(n+1)/2
D. 2^n-1
E. n!
答案:C
解析:找规律,大小为1的有n个,大小为2的有n-1个,。。。,大小为n的有一个,共n*(n+1)/2个。

18. Given the following database table, how many rows will the following SQL statement update?(5 Points)

A. 1
B. 2
C. 3
D. 4
E. 5
答案:B
解析:SQL基本语法。

19. What is the shortest path between node S and node T, given the graph below? Note: the numbers represent the lengths of the connected nodes.(13 Points)

A: 17
B. 18
C. 19
D. 20
E. 21

答案:D
解析:使用贪心、动态规划、暴力等各种策略,都能很快得到答案。

20. Given a set of N balls and one of which is defective (weighs less than others), you are allowed to weigh with a balance 3 times to find the defective. Which of the following are possible N?(13 Points)
A. 12
B. 16
C. 20
D. 24
E. 28
答案:ABCD
解析:小于或等于3^3=27的数都行。
12可以分为6,6一次,3,3,一次,1,1一次。
16可分为5,5一次,如果5,5不相等,继续2,2,一次,1,1一次。如果5,5相等,剩下的3,3一次,1,1一次。
20可分为7,7一次,如果7,7不相等,再3,3一次,1,1一次。如果7,7相等,则剩下的3,3一次,1,1一次。
24可分为9,9一次,如果9,9不相等,轻的那一端再3,3一次,如果3,3相等,则再1,1一次,如果3,3不相等,则轻的那一端1,1一次。如果9,9相等,则剩下的3,3一次,1,1一次。

抱歉!评论已关闭.