微软2013校园招聘笔试试题及详细解答

版权所有,转载请注明出处,谢谢!
http://blog.csdn.net/walkinginthewind/article/details/8770201

(不定项选择题)

1. Which of the following calling conversion(s) support(s) variable-lengt parameter(e.g. printf)?
   A. cdecl
   B. stdcall
   C. pascal
   D. fastcall
解答:printf在VS2010的stdio.h中的声明为
_Check_return_opt_ _CRTIMP int __cdecl printf(_In_z_ _Printf_format_string_ const char * _Format, ...);
即printf为cdecl调用。下面对各种调用简要说明:
各种调用方式的区别主要有参数的压栈顺序,是从左到右还是从右到左;函数执行结束由谁来负责清除调用前压入栈中的参数,调用方还是被调用方;是否使用寄存器传递参数。
(1)cdecl:c/c++默认的调用方式。参数从右向左传递,放在栈中;栈平衡由调用函数来执行;不定参数函数可以使用。C语言中的printf就是典型的cdecl调用方式。因为printf函数不知道具体传入的参数的个数,所以printf内部不能完成平衡栈的操作,只能由被调用方负责平衡栈的操作。printf是通过例如%d、%c、%s等进行参数解析,但它不能确定传入参数个数,如printf("%d\n", 0, "Hello world!")也是合法的,但printf意识不到"Hello world"(实际是首地址)。
(2)stdcall:参数从右向左传递,放在栈中;栈平衡操作由被调用函数执行;不定参数的函数无法使用。Win32 API函数绝大部分都是采用__stdcall调用约定的。WINAPI其实也只是__stacall的一个别名而已。由于被调用函数完成栈平衡平衡操作,因此函数参数个数必须确定,不能使用不定参数。
(3)pascal:参数由左到右的顺序入栈;由被调用函数负责栈平衡操作;也不能使用不定参数。
(4)fastcall: 最左边的两个不大于4字节的参数分别放在ecx和edx寄存器,其余参数仍然从右到左压入栈,但是,对于浮点值、远指针和__int64类型总是通过栈来传递;被调用方平衡栈;不定参数无法使用。

2. What's the output of the following code?
        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
解答:首先,两个成员函数如果只是常量性不同,可以被重载。
先看main函数中的a->f(),由于a不是常量的指针,所以编译器首先匹配到的是void f(),由于此函数是虚函数,因此实行动态绑定,因为a所指的实际类型是class B,所以执行过程中实际调用的是void B::f()。
函数g中的调用,因为参数a是const A*,所以a->f()匹配的是void f() const,由于该函数不是虚函数,因此执行静态绑定,a所指的静态类型是class A,所以执行的是void A::f() const。

3. What is the difference bewteen a linked list and an array?
   A. Search complexity when both are sorted
   B. Dynamically add/remove
   C. Random access efficiency
   D. Data storage type
解答:链表与数组的区别。ABCD都是。
数组:元素在内存中连续;可通过下标随机访问;插入删除元素需要移动大量元素。
链表:元素在内存中不一定连续,通过指针联系在一起;不能随机访问某元素。增加删除简单,只操作指针即可。

4. About the Thread and Process in Windows, which description(s) is(are) correct:
   A. One application in OS must have one Process, but not a necessary to have one Tread
   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
解答:此题考察进

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值