微软Microsoft招聘笔试题及答案
- 格式:doc
- 大小:55.50 KB
- 文档页数:18
笔试题及答案微软1. 问题:请解释什么是递归,并给出一个递归函数的例子。
答案:递归是一种编程技术,它允许一个函数调用自身来解决问题。
递归函数通常有两个主要部分:基本情况和递归情况。
基本情况是递归结束的条件,而递归情况是函数调用自身的地方。
示例代码:```pythondef factorial(n):if n == 0: # 基本情况return 1else: # 递归情况return n * factorial(n - 1)```2. 问题:在C#中,如何实现单例模式?答案:单例模式确保一个类只有一个实例,并提供一个全局访问点。
在C#中,可以通过私有构造函数和静态实例来实现。
示例代码:```csharppublic class Singleton{private static Singleton instance;private Singleton() { } // 私有构造函数public static Singleton GetInstance(){if (instance == null){instance = new Singleton();}return instance;}}```3. 问题:解释什么是闭包,并给出一个JavaScript中的闭包示例。
答案:闭包是一个函数和其周围的状态(词法环境)的组合。
闭包允许函数访问定义在其外部作用域的变量。
示例代码:```javascriptfunction createCounter() {let count = 0;return function() {count += 1;return count;};}const counter = createCounter();console.log(counter()); // 输出:1console.log(counter()); // 输出:2```4. 问题:在Java中,如何实现观察者模式?答案:观察者模式是一种设计模式,允许对象在状态变化时通知其他依赖对象。
第一组1.烧一根不均匀的绳,从头烧到尾总共需要1个小时。
现在有若干条材质相同的绳子,问如何用烧绳的方法来计时一个小时十五分钟呢?2.你有一桶果冻,其中有黄色、绿色、红色三种,闭上眼睛抓取同种颜色的两个。
抓取多少个就可以确定你肯定有两个同一颜色的果冻?3.如果你有无穷多的水,一个3公升的提捅,一个5公升的提捅,两只提捅形状上下都不均匀,问你如何才能准确称出4公升的水?4.一个岔路口分别通向诚实国和说谎国。
来了两个人,已知一个是诚实国的,另一个是说谎国的。
诚实国永远说实话,说谎国永远说谎话。
现在你要去说谎国,但不知道应该走哪条路,需要问这两个人。
请问应该怎么问?5.12个球一个天平,现知道只有一个和其它的重量不同,问怎样称才能用三次就找到那个球。
13个呢?(注意此题并未说明那个球的重量是轻是重,所以需要仔细考虑)6.在9个点上画10条直线,要求每条直线上至少有三个点?7.在一天的24小时之中,时钟的时针、分针和秒针完全重合在一起的时候有几次?都分别是什么时间?你怎样算出来的?8.怎么样种植4棵树木,使其中任意两棵树的距离相等?第二组1.为什么下水道的盖子是圆的?2.中国有多少辆汽车?3.将汽车钥匙插入车门,向哪个方向旋转就可以打开车锁?4.如果你要去掉中国的34个省(含自治区、直辖市和港澳特区及台湾省)中的任何一个,你会去掉哪一个,为什么?5.多少个加油站才能满足中国的所有汽车?6.想象你站在镜子前,请问,为什么镜子中的影象可以颠倒左右,却不能颠倒上下?7.为什么在任何旅馆里,你打开热水,热水都会瞬间倾泻而出?8.你怎样将Excel的用法解释给你的奶奶听?9.你怎样重新改进和设计一个ATM银行自动取款机?10.如果你不得不重新学习一种新的计算机语言,你打算怎样着手来开始?11.如果你的生涯规划中打算在5年内受到奖励,那获取该项奖励的动机是什么?观众是谁?12.如果微软告诉你,我们打算投资五百万美元来启动你的投资计划,你将开始什么样商业计划?为什么?13.如果你能够将全世界的电脑厂商集合在一个办公室里,然后告诉他们将被强迫做一件事,那件事将是什么?第三组1.你让工人为你工作7天,回报是一根金条,这个金条平分成相连的7段,你必须在每天结束的时候给他们一段金条。
1.把二元查找树转变成排序的双向链表题目:输入一棵二元查找树,将该二元查找树转换成一个排序的双向链表。
要求不能创建任何新的结点,只调整指针的指向。
10/ \6 14/ \ / \4 8 12 16转换成双向链表4=6=8=10=12=14=16。
首先我们定义的二元查找树节点的数据结构如下:struct BSTreeNode{int m_nValue; // value of nodeBSTreeNode *m_pLeft; // left child of nodeBSTreeNode *m_pRight; // right child of node};2.设计包含min函数的栈。
定义栈的数据结构,要求添加一个min函数,能够得到栈的最小元素。
要求函数min、push以及pop的时间复杂度都是O(1)。
3.求子数组的最大和题目:输入一个整形数组,数组里有正数也有负数。
数组中连续的一个或多个整数组成一个子数组,每个子数组都有一个和。
求所有子数组的和的最大值。
要求时间复杂度为O(n)。
例如输入的数组为1, -2, 3, 10, -4, 7, 2, -5,和最大的子数组为3, 10, -4, 7, 2,因此输出为该子数组的和18。
4.在二元树中找出和为某一值的所有路径题目:输入一个整数和一棵二元树。
从树的根结点开始往下访问一直到叶结点所经过的所有结点形成一条路径。
打印出和与输入整数相等的所有路径。
例如输入整数22和如下二元树10/ \5 12/ \4 7则打印出两条路径:10, 12和10, 5, 7。
二元树节点的数据结构定义为:struct BinaryTreeNode // a node in the binary tree{int m_nValue; // value of nodeBinaryTreeNode *m_pLeft; // left child of nodeBinaryTreeNode *m_pRight; // right child of node};5.查找最小的k个元素题目:输入n个整数,输出其中最小的k个。
微软社会招聘笔试题题目1:一楼到十楼的每层电梯门口都放着一颗钻石,钻石大小不一。
你乘坐电梯从一楼到十楼,每层楼电梯门都会打开一次,只能拿一次钻石,问:怎样才能拿到最大的一颗﹖应试者不知该怎么办。
考试后主考官并没有明确公布答案,但他对其中一位女士的做法表示赞赏。
那位女士的回答是:选择前五层楼都不拿,观察各层钻石的大小,做到心中有数。
后面五个楼层再选择,选择大小接近前五层楼出现过最大钻石大小的钻石。
这位女士后来在互联网上谈体会时说:“我至今也不知道这道题的准确答案,也许本来就没有准确答案,就是考一下你的思路。
”题目2:有8颗弹子球,其中1颗是“缺陷球”,也就是它比其他的球都重。
你怎样使用天平只通过两次称量就能够找到这个球﹖题目3:“请用一笔画出四根直线,将图上9个点全部联结。
”答案:画一根与水平成45度角的斜线到某一点,然后以此点作为直角三角形两个直角边的交点,向任何一边作直角三角形,就可以把9个点联结起来。
题目4:为什么下水道的盖子是圆的?题目5:想象你再镜子前面,请问,为什么镜子中的影像可以颠倒左右,却不能颠倒上下?题目6:如果你有无穷多的水,一个3夸脱和一个5夸脱的提桶,你如何准确称出4夸脱的水?题目7:你让工人为你工作七天,回报是一根金条。
这根金条已经平分成相连的七段,你必须在每天结束的时候给他们一段金条,如果只允许你两次把金条弄断,你如何给你的工人付工资?题目8:有一辆火车以每小时15公里的速度离开洛杉矶直奔纽约,另一辆火车以每小时20公里的速度从纽约开往洛杉矶。
如果有一只鸟,以30公里每小时的速度和两辆火车同时启动,从洛杉矶出发,碰到另一辆火车后返回,依次在两辆火车之间来回飞行,直到两辆火车相遇,请问这只小鸟飞行了多长距离?题目9:你有四个装药丸的罐子,每个药丸都有一定的质量,被污染的药丸是没被污染药丸的重量+1,只称量一次,如何判断哪个罐子的药被污染了?题目10:一个正三角形的每个角上各有一只蚂蚁。
微软笔试真题一:微软笔试1.简要谈一下您对微软.NET 构架下remoting和webservice两项技术的理解以及实际中的应用。
答:WS主要是可利用HTTP,穿透防火墙。
而Remoting可以利用TCP/IP,二进制传送提高效率。
微软笔试2.公司要求开发一个继承System.Windows.Forms.ListView类的组件,要求达到以下的特殊功能:点击ListView各列列头时,能按照点击列的每行值进行重排视图中的所有行(排序的方式如DataGrid相似)。
根据您的知识,请简要谈一下您的思路答:根据点击的列头,包该列的ID取出,按照该ID排序后,在给绑定到ListView中。
微软笔试3.写出一条Sql语句:取出表A中第31到第40记录(SQLServer,以自动增长的ID作为主键,注意:ID可能不是连续的。
答:解1: select top 10 * from A where id not in (select top 30 idfrom A)解2: select top 10 * from A where id >(select max(id) from (selecttop 30 id from A )as A)微软笔试4.面向对象的语言具有________性、_________性、________性答:封装、继承、多态。
微软笔试5.能用foreach遍历访问的对象需要实现________________接口或声明________________方法的类型。
答:IEnumerable 、GetEnumerator。
微软笔试6.GC是什么? 为什么要有GC?答:GC是垃圾收集器。
程序员不用担心内存管理,因为垃圾收集器会自动进行管理。
要请求垃圾收集,可以调用下面的方法之一:System.gc()Runtime.getRuntime().gc()微软笔试7.String s = new String("xyz");创建了几个String Object?答:两个对象,一个是“xyx”,一个是指向“xyx”的引用对象s。
大家看看题目吧,我在网上找的,答案未必正确,可以讨论讨论:根据/bbscon,board,JobForum,file,M.1333796036.A.html以及自己的记忆进行的修改。
下面有些和原话有部分出入,但不影响理解。
不定向选择题,全答对得所有分,部分答对给一个分,答错扣分。
越往后题的分值相对增大,做错扣的也越狠。
Choose部分是我自己做的答案,非标准答案.有些题目选项记不起来了,非常抱歉.1.Selection sort 80 items, after 32 iterations, how many positions of items are inits final position?A.16B.31 C32 D39 E40Choose:C2.Which is used in sync(synchronization)process//thread to avoid race conditionin operation system?A.MutexB.mailboxC.SemaphoreD.local procedure callChoose:AC3.Size of a stack is 5, input is a sequence 1, 2, …, 7, which is possible output?A.1234567B. 7654321C.5643721D. 1765432E.3217564Choose:AC4.010111001 * 011001 + 1101110 = ?(我的试卷是01011000*0111001+1101110=?)A.0001010000111111B.0101011101110011C.0011010000110101Choose:A5.What is the output of the follow code?voidmain(intargc, char* argv[]) {int i = 11;intconst *p = &i;p++;print(“%d”,*p);}A. 11B. 12C.Garbage valueD. Comipler errorE. None of above Choose:C解析:这个笔者在程序里面运行了,确实得到一个这样的数据-8589934606.Which code is correct?A. intf(){int *a = new int(3);return *a;}C.vector<int>f() {vector<int> v(3);return v;}D. void f(int *ret){int a[3] ={1,2,3};ret=a;return ;}E.None of aboveChoose:AC这个题我都在程序里面运行了,下面是我的理解解析:A中注意newint的后面是()而不是[],()的返回结果为3,[]对应的返还结果为一个Garbagevalue,按这个说来这个选项也可姑且算为对(可以认为这个函数就是返还一个3)B 由于在函数内部定义的a,函数结束后空间就释放了,(空间内的值暂时还是1,2,3,但是当别的代码需要分配空间的时候,就可能会用新的值覆盖掉1,2,3)。
2023年微软招聘笔试试题及答案第一题题目:请解释什么是云计算?答案:云计算是一种通过网络提供计算资源和服务的模式。
它允许用户通过互联网访问虚拟化的计算资源,如计算能力、存储空间和软件应用。
这些资源可以根据需要进行动态分配和管理,为用户提供灵活、可扩展和可靠的计算环境。
第二题题目:请简述微软Azure的主要产品和服务。
答案:微软Azure是一种云计算平台,它提供一系列的产品和服务,包括:1. 虚拟机:Azure提供可扩展的虚拟机实例,用户可以根据需要创建和管理虚拟机来运行各种应用程序和服务。
2. 存储:Azure提供持久性存储服务,包括Blob存储、文件存储和表格存储,可以用于存储和访问各种数据。
3. 数据库:Azure提供多种数据库服务,包括SQL数据库、Cosmos DB和Azure数据库服务,适用于不同类型的数据存储和管理需求。
4. 人工智能:Azure提供人工智能服务,如计算机视觉、语音识别和自然语言处理,使开发人员能够构建智能应用程序和系统。
5. 网络:Azure提供虚拟网络服务,包括虚拟网络、子网和网络安全组,用户可以在Azure中创建可扩展的网络架构。
6. 安全和合规性:Azure提供安全和合规性服务,包括身份验证、访问控制、数据加密和合规性认证,以帮助用户确保数据的安全性和合规性。
第三题题目:请解释什么是软件开发生命周期(SDLC)?答案:软件开发生命周期(SDLC)是指软件开发过程中的一系列阶段和活动。
这些阶段包括需求分析、系统设计、编码、测试、部署和维护。
SDLC旨在确保软件开发过程的组织性、可控性和可重复性,以确保交付高质量的软件产品。
第四题题目:请解释什么是敏捷开发(Agile Development)?答案:敏捷开发是一种软件开发方法论,强调在开发过程中的灵活性、协作和快速迭代。
敏捷开发通过将开发过程分解为多个短期迭代周期(一般为2到4周),每个周期中完成一部分功能,以满足客户需求。
1int n = 0;while (x)2{3xx = x & (x - 1);4n++;5}6return n;微软笔试题:快速求取一个整数的7倍乘法相对比较慢,所以快速的方法就是将这个乘法转换成加减法和移位操作。
可以将此整数先左移三位(×8)然后再减去原值:X << 3 - X。
微软笔试题:判断一个数是不是2的n次幂设要判断的数是无符号整数X。
首先判断X是否为0,如果为0则不是2的n次幂,返回。
X和X-1进行按位与操作,如果结果是0,则说明这个数是2的n次幂;如果结果非0,则说明这个数不是2 的n次幂。
证明:如果是2的n次幂,则此数用二进制表示时只有一位是1,其它都是0。
减1后,此位变成0,后面的位变成1,所以按位与后结果是0。
如果不是2的n次幂,则此数用二进制表示时有多位是1。
减1后,只有最后一个1变成0,前面的 1还是1,所以按位与后结果不是0。
微软笔试题:三只蚂蚁不相撞的概率是多少在三角形的三个顶点上各有一只蚂蚁,它们向另一个顶点运动,目标随机(可能为另外两个顶点的任意一个)。
问三只蚂蚁不相撞的概率是多少?如果蚂蚁顺时针爬行记为0,逆时针爬行记为1。
那么三只蚂蚁的状态可能为000,001,...,110,111中的任意一个,且为每种状态的概率相等。
在这8种状态中,只有000和111可以避免相撞,所以蚂蚁不相撞的概率是1/4。
微软笔试题:判断数组中是否包含重复数字给定一个长度为N的数组,其中每个元素的取值范围都是1到N。
判断数组中是否有重复的数字。
(原数组不必保留)给定一个长度为N的数组,其中每个元素的取值范围都是1到N。
判断数组中是否有重复的数字。
(原数组不必保留)微软笔试题:如何将蛋糕切成相等的两份一块长方形的蛋糕,其中有一个小长方形的空洞(角度任意)。
使用一把直刀,如何一刀将蛋糕切成相等的两份?通过长方形中心的的任意直线都能将长方形等分,所以连接两个长方形的中心点的直线可以等分这个蛋糕。
微软考试题答案考生姓名:____________考试日期:____________考试编号:____________考试时长:____________考试说明:请仔细阅读题目,并在规定时间内完成所有试题。
所有答案必须写在答题卡上,否则视为无效。
一、选择题(每题2分,共20分)1. 微软公司(Microsoft)的创始人是:A. 史蒂夫·乔布斯B. 比尔·盖茨C. 拉里·佩奇D. 马克·扎克伯格2. Windows操作系统是由以下哪个公司开发的:A. 苹果公司B. 微软公司C. 谷歌公司D. 亚马逊公司3. 下列哪个不是微软Office套件中的应用程序:A. WordB. ExcelC. PowerPointD. Photoshop4. 微软的云计算服务被称为:A. Google CloudB. AzureC. AWSD. iCloud5. 微软最新推出的操作系统是:A. Windows 7B. Windows 8C. Windows 10D. Windows 116. 微软的搜索引擎是:A. GoogleB. BingC. YahooD. Baidu7. 微软的Xbox游戏机是用于:A. 办公软件B. 视频编辑C. 游戏娱乐D. 网络安全8. 微软的Skype是一款:A. 浏览器B. 邮件客户端C. 即时通讯软件D. 图像编辑软件9. 微软的Visual Studio是一个:A. 操作系统B. 浏览器C. 开发环境D. 数据库管理系统10. 下列哪个是微软的编程语言:A. JavaB. C#C. PythonD. Ruby二、填空题(每空2分,共20分)11. 微软公司的总部设在美国的__________州。
12. Windows操作系统的默认文件浏览器是__________。
13. 微软的Office套件中,用于制作幻灯片的软件是__________。
14. 微软的云计算服务Azure支持__________操作系统。
微软招聘测试题只有5分钟,超过5分钟就放弃,因为你绝对不会被微软招聘.这是微软招聘时的智力测试!!!!超过5分钟,淘汰!!!!test 1烧一根不均匀的绳需用一个小时,如何用它来判断半个小时?test 2。
请仅用一笔画四根直线,将上图9各点全部连接。
test 3对一批编号为1~100全部开关朝上(开)的灯进行以下操作:凡是1的倍数反方向拨一次开关;2的倍数反方向又拨一次开关;3的倍数反方向又拨一次开关。
问:最后为关熄状态的灯的编号。
职务经历表的格式相当自由。
只要格式正确,其内容可随意发挥。
只不过,经历表容易显露出应征者之个性好坏。
所以,只要能适当的将自己魅力及自信表现出来,应可在求职过程中取得先机。
单是要将经历及经验简单扼要的写出,是不如想象中的容易。
如何制作出一份成功的职务经历表,是常令求职者感到头痛的问题。
职务经历表能够将你所具备之业务经验,参加过之培训会,前面工作所得之奖项等明白列出。
就算无特别要求,最好也能够和履历表一同提出。
职务经历书的格式,基本上是没有限制的。
但这却不代表任何体裁皆可使用。
无法充分表达重点,或者是使用劣质纸张,皆有可能让面试者对你的印象大打折扣。
只有得体又能表现自我之职务经历书,方能帮你迈出成功的第一步。
首先,从决定书写格式开始吧!接下来所举出三种书写格式,乃一般最常使用之类型。
请选出最能表达自己经历之格式吧!编年体形式最普遍的形式优点:编年体形式乃职务经历中之入、离公司,职务更换,转调工作,升迁等,依发生时间顺序来编排。
也就是制成年代表。
此方式可清楚明白的将经历表示出来。
由于制作方式简单,乃最常被人使用之形式。
只是无法明述经历中之吸引人处。
书写要领:以进入公司,职务异动,升迁,转调工作等为段落,分别简述各时期之业务内容,职务,实迹等。
文体采条列方式书写。
须考虑到空白及行距,让看的人能一目了然。
文章形式适合经历少,有特殊情形的人优点:以文章来表示职务经历。
【1】假设有一个池塘,里面有无穷多的水。
现有2个空水壶,容积分别为5升和6升。
问题是如何只用这2个水壶从池塘里取得3升的水。
【2】周雯的妈妈是豫林水泥厂的化验员。
一天,周雯来到化验室做作业。
做完后想出去玩。
"等等,妈妈还要考你一个题目,"她接着说,"你看这6只做化验用的玻璃杯,前面3只盛满了水,后面3只是空的。
你能只移动1只玻璃杯,就便盛满水的杯子和空杯子间隔起来吗?" 爱动脑筋的周雯,是学校里有名的"小机灵",她只想了一会儿就做到了。
请你想想看,"小机灵"是怎样做的?【3】三个小伙子同时爱上了一个姑娘,为了决定他们谁能娶这个姑娘,他们决定用手枪进行一次决斗。
小李的命中率是30%,小黄比他好些,命中率是50%,最出色的枪手是小林,他从不失误,命中率是100%。
由于这个显而易见的事实,为公平起见,他们决定按这样的顺序:小李先开枪,小黄第二,小林最后。
然后这样循环,直到他们只剩下一个人。
那么这三个人中谁活下来的机会最大呢?他们都应该采取什么样的策略?【4】一间囚房里关押着两个犯人。
每天监狱都会为这间囚房提供一罐汤,让这两个犯人自己来分。
起初,这两个人经常会发生争执,因为他们总是有人认为对方的汤比自己的多。
后来他们找到了一个两全其美的办法:一个人分汤,让另一个人先选。
于是争端就这么解决了。
可是,现在这间囚房里又加进来一个新犯人,现在是三个人来分汤。
必须寻找一个新的方法来维持他们之间的和平。
该怎么办呢?按:心理问题,不是逻辑问题【5】在一张长方形的桌面上放了n个一样大小的圆形硬币。
这些硬币中可能有一些不完全在桌面内,也可能有一些彼此重叠;当再多放一个硬币而它的圆心在桌面内时,新放的硬币便必定与原先某些硬币重叠。
请证明整个桌面可以用4n个硬币完全覆盖【6】一个球、一把长度大约是球的直径2/3长度的直尺.你怎样测出球的半径?方法很多,看看谁的比较巧妙【7】五个大小相同的一元人民币硬币。
微软入职测试题
1.编程题:请写一个函数,将输入的字符串反转并输出。
2.逻辑题:在一张纸上,有100个点,每个点都有一个坐标。
现在请你给每
个点涂上颜色,使得任意两个相邻的点不同色。
请问最少需要涂多少个点?
3.团队题:假设你被分配到一个小团队,但是团队中有一个成员表现不佳,
影响了整个项目的进度。
你会如何处理这个问题?
4.沟通题:如果你与一个同事意见不合,你会如何处理这个问题?
5.商业题:假设你是一家电商公司的产品经理,现在公司想要扩展业务到新
的市场,你会如何制定产品策略?
6.系统设计题:请设计一个能够处理大量请求的高可用系统,并且能够支持
多种语言和平台。
7.项目管理题:请描述一下你如何使用敏捷开发方法管理一个复杂的项目,
并确保按时交付。
8.文化题:在微软,我们重视多元文化和包容性。
请分享一个你在之前的经
历中如何促进团队中的多元化和包容性的例子。
9.领导力题:如果你被选为一个团队的负责人,你会如何激励团队成员并促
进他们的职业发展?
10.技术支持题:请描述一下你如何解决一个复杂的网络问题。
微软售前笔试题答案微软公司售前技术支持笔试题答案一、选择题1. 在微软Azure云服务中,用于存储非结构化数据的对象存储解决方案是什么?A. Azure Blob StorageB. Azure Queue StorageC. Azure File StorageD. Azure Table Storage答案:A2. 微软Power BI主要用于什么目的?A. 数据库管理B. 数据可视化和报告C. 企业资源规划D. 客户关系管理答案:B3. 下列哪个不是微软Dynamics 365的组成部分?A. 销售管理B. 客户服务C. 财务管理D. 社交网络服务答案:D4. 在微软的操作系统中,哪个特性允许用户在同一时间使用多个桌面?A. 虚拟桌面B. 动态锁定C. 多任务视图D. 快速启动答案:A5. 微软Teams是一个什么类型的应用程序?A. 项目管理B. 协作平台C. 数据分析D. 网络安全答案:B二、填空题1. 微软的云计算平台称为________,它提供了一系列的服务,包括计算、分析、存储和网络。
答案:Azure2. 在微软的Windows操作系统中,用于保护用户隐私和提高安全性的特性之一是________。
答案:Windows Hello3. 微软的人工智能助手名为________,它可以帮助用户执行各种任务,如设置提醒、回答问题等。
答案:Cortana4. 微软的数据库服务器产品名为________,它支持多种数据库引擎,如关系型数据库和文档数据库。
答案:SQL Server5. 微软的云存储服务________允许用户在不同设备间同步文件和文档。
答案:OneDrive三、简答题1. 描述微软Azure云服务中的虚拟机功能及其用途。
答:Azure虚拟机是一种云计算服务,它允许用户在Azure云平台上创建和管理虚拟化的服务器环境。
用户可以选择各种操作系统和应用程序,根据需要配置资源,并快速部署应用程序和服务。
微软测试题及答案一、选择题(每题2分,共20分)1. 微软公司是在哪一年成立的?A. 1975年B. 1980年C. 1985年D. 1990年答案:A2. Windows操作系统是由哪家公司开发的?A. 苹果公司B. 谷歌公司C. 微软公司D. 亚马逊公司答案:C3. 下列哪个不是微软的产品?A. WindowsB. OfficeC. XboxD. Android答案:D4. 微软的创始人是以下哪位?A. 史蒂夫·乔布斯B. 比尔·盖茨C. 拉里·佩奇D. 马克·扎克伯格答案:B5. 微软的总部设在哪个国家?A. 美国B. 英国C. 中国D. 印度答案:A6. 下列哪个不是微软的云计算服务?A. AzureB. AWSC. Google CloudD. Office 365答案:C7. 微软的哪种编程语言是面向对象的?A. CB. C++C. JavaD. Python答案:B8. 微软的哪种操作系统是为移动设备设计的?A. Windows XPB. Windows 7C. Windows 8D. Windows Phone答案:D9. 微软的哪种服务是提供在线存储和文件同步的?A. OneDriveB. DropboxC. Google DriveD. iCloud答案:A10. 微软的哪种编程语言主要用于网页开发?A. C#B. JavaScriptC. RubyD. PHP答案:B二、填空题(每题1分,共10分)1. 微软的第一款操作系统是________。
答案:MS-DOS2. 微软的办公软件套装被称为________。
答案:Microsoft Office3. 微软的搜索引擎是________。
答案:Bing4. 微软的浏览器是________。
答案:Microsoft Edge5. 微软的编程语言C#的“#”读作________。
答案:Sharp6. 微软的Xbox游戏机是为________平台设计的。
微软笔试Question 1. (单选)以下关于MAC的说法中错误的是1. MAC地址在每次启动后都会改变2. MAC地址一共有48比特,它们从出厂时就被固化在网卡中3. MAC地址也称做物理地址,或通常所说的计算机的硬件地址微软笔试Question 2. (单选)交换机不具有下面哪项功能1. 交换机不具有下面哪项功能2. 回路避免3. 路由转发4. 地址学习微软笔试Question 3. (单选)以下不属于私有地址的网段是(4)1. 10.0.0.0/82. 172.16.0.0/123. 192.168.0.0/164. 224.0.0.0/8微软笔试Question 4. (单选)下面哪种网络设备用来隔绝广播1. 集线器2. 交换机3. 路由器微软笔试Question 5. (单选)汉诺塔(Hanoi)问题中令h(n)为从A移动n个金片到C上所用的次数,则递归方程为1. h(n)=2hn-12. h(n) = 2h(n-1)+13. h(n)=2^n-n*h-14. h(n)=2h*n-1微软笔试Question 6. (单选)启发式搜索一般是何种算法的改进1. 深度优先搜索2. 广度优先搜索3. 动态规划4. 贪婪法微软笔试Question 7. (单选)假设一棵二叉树的后序遍历序列为DGJHEBIFCA ,中序遍历序列为DBGEHJACIF ,则其前序遍历序列为( ) 。
1. ABCDEFGHIJ2. ABDEGHJCFI3. ABDEGHJFIC4. ABDEGJHCFI微软笔试Question 8. (单选)散列函数有一个共同性质,即函数值应按()取其值域的每一个值;1. 最大概率2. 最小概率3. 同等概率4. 平均概率微软笔试Question 9. (单选)下面描述中正确的为:1. 线性表的逻辑顺序与物理顺序总是一致的。
2. 线性表的顺序存储表示优于链式存储表示。
3. 线性表若采用链式存储表示时所有结点之间的存储单元地址可连续可不连续。
微软笔试试题+很经典啊(总2页)--本页仅作为文档封面,使用时请直接删除即可----内页可以根据需求调整合适字体及大小--微软招聘心理智力测试题简历, 微软据《泰晤士报》报道,全球软件业巨头微软公司在招聘员工时,首先从心理入手,全面考核应聘者是否具有敏捷的反应和创造力。
最新出版的一本书披露了应聘者必答的一些“希奇古怪”的问题。
微软招聘难题多多世界上最大的软件公司——微软公司,已形成其独特的(也有人认为是古怪的)招聘方式。
该公司每个月会收到万份简历。
无须人工介入,计算机会通过关键词的方式仔细搜索,然后将其录入数据库。
有前景的简历会给应聘者赢得一次与面试官对话的机会,一般是通过电话。
最后符合要求的应聘者才会获准前往位于华盛顿州雷蒙德的微软总部,接受一整天具有高难度的马拉松式面试。
微软公司网站上写着:“我们期待着具有独创性、开拓性的智者加入我们的队伍。
我们的面试程序也是为网罗这样的人才专门设计的。
”一般来讲,招聘人员会逐项提出所谓的“微软问题”。
这个问题或是数学方面的问题——只有一个“正确”答案,或是开放式问题。
无论哪种情况,招聘人员至少应该是对你回答问题的方式和对这个问题本身同样感兴趣。
微软公司以提出难题的方式招聘员工,这一点为这个构筑了数字神话的“巨无霸”又增添了一份魅力。
微软公司员工声称,该公司对所有人都一视同仁,不偏不倚。
重要的是你的逻辑思维能力、想象力和解决问题的能力如何。
请你为盖茨设计浴室微软公司面试时所提出的问题已形成了自己独特的风格,不断层出不穷地推出新花样。
这本书中只摘录了一些被广为转载的问题,至少在网站上是这样,一些人喜欢将微软公司面试时问的难题“收集”起来,然后在网上公开。
此外,微软公司问的多数问题也被其他公司广泛使用。
随着提问的难题越来越多,其它许多问题也已加入其中。
在时间压力下,有些极难的问题,应聘者在仓促之间无法马上做出回答。
如果确有人答出,只能说明此人高人一筹。
而这个极难的问题就是:微软最难的面试题你会怎样为比尔盖茨设计浴室?回答这个问题时有两个关键点。
Interview QuizWindows Section1.Which of the following disks contains partitions?A.BasicB.DynamicC.PrimaryD.Logical2.Which of the following are advantages of the NTFS file system over FAT32 and FAT? Eachcorrect answer represents a part of the solution. Choose two.A.Support for Encrypting File System (EFS).B.Support for dual-booting.C.Support for audio files.D.Support for file and folder level permissions.3. Which of the following is the difference between local and network applications?A. A local application is loaded in a local computer and accessed from a remote computer, whereas a network application is loaded in a local computer and accessed only by the local computer.B. A network application is loaded in a local computer and accessed from a remote computer, whereas a local application is loaded in a local computer and accessed only by the local computer.C. A network application is loaded in a remote computer, whereas a local application is loaded in a local computer.D. A network application is loaded in a local computer, whereas a local application is loaded in an administrative computer.4.In Windows 7, what is the difference between a library and a folder?A. A folder is a container for storing libraries; a library provides a single view of multiple foldersand their contents.B. A Library is a container for storing files; a folder provides a single view of multiple folders andtheir contents.C.There is no difference between a library and a folder.D. A folder is a container for storing files; a library provides a single view of multiple folders andtheir contents.5.Which of the following are the advantages of the group policy? Each correct answerrepresents a complete solution. Choose all that apply.A.It is very secure because only the administrator is authorized to make changes.B.It provides streamlined deployment because installation is fully automated withoutinteraction.C.Its domain, site, and organizational unit settings reflect all associated users and computers.D.It is possible to change the policy settings by removing the old one and rewriting thechanges.6.Which interface is mainly used for high-speed communications and isochronous real-timedata transfer?A.eSATABC.IEEE 1394D.iSCSI7.Which of the following devices is used to explain the characteristic of a computer bus, ordevice specification, which facilitates the discovery of a hardware component in a system, with no need of physical device configuration?work PrinterB.Plug and PlayC.Local PrinterD.Plug and display8.Which of the following are the advantages of the Print to file option? Each correct answerrepresents a complete solution. Choose all that apply.A. A document can be sent to a commercial printer.B. A document can be printed later.C. A document can be sent to any printer.D. A document can be sent to someone who has the same printer.9.All servers in your environment run Windows Server 2003. You plan to require the use of asmart card for remote access. You need to choose an authentication protocol. Which protocol should you use?A.PAPB.EAP-TLSC.MS-CHAPD.MS-CHAP v210.Your company has an Active Directory directory service domain. All servers on your network run Windows Server 2003. All client computers run Windows XP Professional.You disable the LAN Manager network authentication protocol and LM hash support. You need to ensure that LM hashes are completely removed from Active Directory.What should you do?A. Log off all users from the client computers.B. Force a password change for all domain users.C. Run the gpupdate /force command on the client computers.D. Disable the Store password using reversible encryption setting.11.Your company has a single Active Directory directory service domain. All servers in yourenvironment run Windows Server 2003. Client computers run Windows XP. Your network has multiple subnets. You configure a server to run the Microsoft Baseline Security Analyzer (MBSA). You plan to create a Windows Firewall exception policy to allow remote scanning of security updates on all client computers. You need to specify the ports that the policy must allow to open. Which ports should you specify?A.TCP ports 80, 135, and 443B.TCP ports 80, 443, and 8530C.TCP ports 135, 139, and 445D.TCP ports 139, 389, and 3248Security Section1. Which of the following contains a tree of domain names?A. Domain name spaceB. Domain name formulationC. Domain Name SystemD. Authoritative name server2.Which of the following protects against unauthorized access to confidential information viaencryption and works at the network layer?A.FirewallB.NATC.IPSecD.MAC address3.Which of the following states that a user should never be given more privileges than arerequired to carry out a task?A.Security through obscurityB.Segregation of dutiesC.Principle of least privilegeD.Role-based security4.Which of the following are the major components of the IPsec protocol? Each correct answerrepresents a complete solution. Choose all that apply.A.Encapsulating Security Payload (ESP)B.Authentication Header (AH)C.Internet Encryption Key (IEK)D.Internet Key Exchange (IKE)5.The stronger password is a critical element in the security plan. Which of the following arethe characteristics used to make up a strong password?A.It contains more than seven hundred characters and does not contain the user name, realname, or any name that can be guessed by the attacker easily.B.It contains more than seven characters and does not contain the user name, real name, oranyname that can be guessed by the attacker easily.C.It contains the user name, real name, or any name that can be remembered easily and doesnot contain more than seven characters.D.It contains more than seven characters and the user name, real name, or any name.6.Which of the following are types of password policies of Windows 7? Each correct answerrepresents a complete solution. Choose all that apply.A.Store Password Using Reversible EncryptionB.Minimum Password Lengther Name LengthD.Password Must Meet Complexity Requirements7.Which of the following is defined as a digitally signed statement used to authenticate and tosecure information on open networks?A.KerberosB.Public certificateC.Single sign-on (SSO)D.SEAL8.Which of the following ports is used by the IMAP4 protocol?A.443B.53C.143D.1109.Which of the following is the process of keeping track of a user's activity while accessingnetwork resources?A.AuthenticationB.AuditingC.SpoofingD.Biometrics10.Which of the following can be implemented to ensure that the computers are using latestsecurity updates?A.HardeningB.Windows Software Update ServicesC.Microsoft Baseline Security AnalyzerD.Domain Name System11.Which of the following protocols is used to secure workstation and computer authenticationacross the network?A.TCP/IPwork Directory Access ProtocolC.KerberosD.Lightweight Directory Access Protocol12.Which of the following types of Network Address Translation (NAT) uses a pool of public IPaddresses?A.Static NATB.Port Address Translation (PAT)C.Dynamic NATD.Cache NAT13.Which of the following MMC snap-in consoles is used to administer the replication ofdirectory data among all sites in an Active Directory Domain Services (AD DS) forest?A.Active Directory Domains and TrustsB.Active Directory Administrative CenterC.Group Policy Management ConsoleD.Active Directory Sites and Services14.Which of the following is a central, secure database in which Windows stores all hardwareconfiguration information, software configuration information, and system security policies?A.RegistryB.Program files folderC.DLL fileD.Configuration file15.Which of the following statements about Network Address Translation (NAT) are true? Eachcorrect answer represents a complete solution. Choose two.A.It allows the computers in a private network to share a global, ISP assigned address toconnect to the Internet.B.It provides added security by using Internet access to deny or permit certain traffic from theBastion Host.C.It allows external network clients access to internal services.D.It reduces the need for globally unique IP addresses.16.Which of the following is a networking protocol that provides centralized Authentication,Authorization, and Accounting management for computers to connect and use a network service?A.PEAPB.RADIUSC.KerberosD.MS-CHAP v217.Which of the following functions are performed by a firewall? Each correct answerrepresents a complete solution. Choose all that apply.A. It blocks unwanted traffic.B. It hides vulnerable computers that are exposed to the Internet.C. It enhances security through various methods, including packet filtering, circuit-level filtering, and application filtering.D. It logs traffic to and from the private network.18.Which of the following root keys stores information about registered applications?A.HKEY_USERSB.HKEY_CLASSES_ROOTC.HKEY_CURRENT_CONFIGD.HKEY_CURRENT_USER19.Which of the following is a collection or list of user accounts or computer accounts?A.GroupB.Active DirectoryC.DomainD.Public folder20.Which of the following is a set of rules that control the working environment of useraccounts and computer accounts?A. Mandatory Access ControlB. Access control listC. Group PolicyD. Intrusion detection systemNetwork Section1. Which VPN technology is the most common and the easiest to set up?A. PPTPB. L2TP with IPSecC. SSTPD. CHAP2. What port does L2TP use?A. 501B. 1723C. 1701D. 4433.Which type of firewall blocks packets based on rules that are based on IP addresses or ports?A.packet filteringB.stateful packet inspectionC.NAT filteringD.Application-level gateway4.What acts as a middleman that translates between internal and external addresses and thatcaches previously accessed web pages so that it can provide those more quickly in the future?A.NAT serverB.stateful packet inspectorC.proxy serverD.NIDS5.What type of firewall works on the Session layer that creates a connection and allowspackets to flow between the two hosts without further checking?A.proxy serverB.application firewallC.NAT filteringD.circuit-level gateway6.What type of configuration creates a DMZ between two firewalls?A.Gateway NetworkB.Perimeter NetworkC.DMZD.RADIAUS Server7.X.25 and Frame Relay are examples of what type of WAN technology?A.circuit switchingB.connection switchingC.packet switchingwork switching8.What model is used to describe how data communication occurs between hosts?A.server-centric modelB.workgroup modelC.peer-to-peer modelD.OSI reference model9.Which layer in the OSI model do MAC addresses and switches use?A.PhysicalB.Data LinkworkD.Transport10.Which layer of the OSI model includes VLANs?A.PhysicalB.Data LinkworkD.Transport11.Which is the most secure encryption used in wireless networks?A.WEPB.WPAC.WPA2D.802.1x12.What type of address is 169.254.32.23?A. APIPAB. multicast addressC. anycast addressD. broadcast address13.You have a computer that cannot connect to a server. When you look at the IP configuration,the host has an address of 169.32.54.2. What is the problem?A.The host cannot find a DHCP server.B.The host is set to multicast.C.The host is currently broadcasting.D.The host cannot find a domain controller.14.You are a network administrator for your company. The company has a main office and onebranch office. The network consists of a single Active Directory domain. All servers run Windows Server 2003. The company needs to connect the main office network and the branch office network by using Routing and Remote Access servers at each office. The networks will be connected by a VPN connection over the Internet.The company's written security policy includes the following requirements for VPN connections over the Internet. All data must be encrypted with end-to-end encryption. VPN connection authentication must be at the computer level. Credential information must not be transmitted over the Internet as part of the authentication process.You need to configure security for VPN connection between the main office and the branch office. You need to comply with the written security policy.What should you do?e an L2TP connection with MS-CHAP v2 authentication.e a PPTP connection with EAP-TLS authentication.e an L2TP connection with EAP-TLS authentication.e a PPTP connection with MS-CHAP v2 authentication.Reading SectionKernel Mode vs. User ModeTo protect user applications from accessing and/or modifying critical operating system data,Windows uses two processor access modes (even if the processor on which Windows is running supports more than two): user mode and kernel mode. User application code runs in user mode, whereas operating system code (such as system services and device drivers) runs in kernel mode. Kernel mode refers to a mode of execution in a processor that grants access to all system memory and all CPU instructions. By providing the operating system software with a higher privilege level than the application software has, the processor provides a necessary foundation for operating system designers to ensure that a misbehaving application can’t disrupt the stability of the system as a whole.---------------------------------------Note The architectures of the x86 and x64 processors define four privilege levels (or rings) to protect system code and data from being overwritten either inadvertently or maliciously by code of lesser privilege. Windows uses privilege level 0 (or ring 0) for kernel mode and privilege level 3 (or ring 3) for user mode. The reason Windows uses only two levels is that some hardware architectures that were supported in the past (such as Compaq Alpha and Silicon Graphics MIPS) implemented only two privilege levels.---------------------------------------Although each Windows process has its own private memory space, the kernel-mode operating system and device driver code share a single virtual address space. Each page in virtual memory is tagged to indicate what access mode the processor must be in to read and/or write the page. Pages in system space can be accessed only from kernel mode, whereas all pages in the user address space are accessible from user mode. Read-only pages (such as those that contain static data) are not writable from any mode. Additionally, on processors that support no-execute memory protection, Windows marks pages containing data as nonexecutable, thus preventing inadvertent or malicious code execution in data areas.32-bit Windows doesn’t pr ovide any protection to private read/write system memory being used by components running in kernel mode. In other words, once in kernel mode, operating system and device driver code has complete access to system space memory and can bypass Windows security to access objects. Because the bulk of the Windows operating system code runs in kernel mode, it is vital that components that run in kernel mode be carefully designed and tested to ensure that they don’t violate system security or cause system instability.This lack of protection also emphasizes the need to take care when loading a third-party device driver, because once in kernel mode the software has complete access to all operating system data. This weakness was one of the reasons behind the driver-signing mechanism introduced in Windows, which warns (and, if configured as such, blocks) the user if an attempt is made to add an unsigned Plug and Play driver.On 64-bit versions of Windows, the Kernel Mode Code Signing (KMCS) policy dictates that any 64-bit device drivers (not just Plug and Play) must be signed with a cryptographic key assigned by one of the major code certification authorities. The user cannot explicitly force the installation of an unsigned driver, even as an administrator, but, as a one-time exception, this restriction can be disabled manually at boot time by pressing F8 and choosing the advanced boot option Disable Driver Signature Enforcement. This causes a watermark on the desktop wallpaper and certain digital rights management (DRM) features to be disabled.In system architecture, user applications switch from user mode to kernel mode when theymake a system service call. For example, a Windows ReadFile function eventually needs to call the internal Windows routine that actually handles reading data from a file. That routine, because it accesses internal system data structures, must run in kernel mode. The transition from user mode to kernel mode is accomplished by the use of a special processor instruction that causes the processor to switch to kernel mode and enter the system service dispatching code in the kernel which calls the appropriate internal function in Ntoskrnl.exe or Win32k.sys. Before returning control to the user thread, the processor mode is switched back to user mode. In this way, the operating system protects itself and its data from perusal and modification by user processes.---------------------------------------Note A transition from user mode to kernel mode (and back) does not affect thread scheduling per se—a mode transition is not a context switch.---------------------------------------Thus, it’s normal for a user thread to spend part of its time executing in user mode and part in kernel mode. In fact, because the bulk of the graphics and windowing system also runs in kernel mode, graphics-intensive applications spend more of their time in kernel mode than in user mode. An easy way to test this is to run a graphics-intensive application such as Microsoft Paint or Microsoft Chess Titans and watch the time split between user mode and kernel mode using one of the performance counters. More advanced applications can use newer technologies such as Direct2D and compositing, which perform bulk computations in user mode and send only the raw surface data to the kernel, reducing the time spent transitioning between user and kernel modes.Question: Please explain Kernel Mode and User Mode with your language. (Write the answer with Chinese)。
微软Microsoft招聘笔试题及答案1.求下面函数的返回值int func(x){int countx = 0;while(x){countx ++;x = x&(x-1);}return countx;}假定x = 9999。
答案:8思路:将x转化为2进制,看含有的1的个数。
2. 什么是“引用〞?申明和使用“引用〞要注意哪些问题?答:引用就是某个目标变量的“别名〞(alias),对应用的操作与对变量直接操作效果完全一样。
申明一个引用的时候,切记要对其进展初始化。
引用声明完毕后,相当于目标变量名有两个名称,即该目标原名称和引用名,不能再把该引用名作为其他变量名的别名。
声明一个引用,不是新定义了一个变量,它只表示该引用名是目标变量名的一个别名,它本身不是一种数据类型,因此引用本身不占存储单元,系统也不给引用分配存储单元。
不能建立数组的引用。
3. 将“引用〞作为函数参数有哪些特点?〔1〕传递引用给函数与传递指针的效果是一样的。
这时,被调函数的形参就成为原来主调函数中的实参变量或对象的一个别名来使用,所以在被调函数中对形参变量的操作就是对其相应的目标对象〔在主调函数中〕的操作。
〔2〕使用引用传递函数的参数,在内存中并没有产生实参的副本,它是直接对实参操作;而使用一般变量传递函数的参数,当发生函数调用时,需要给形参分配存储单元,形参变量是实参变量的副本;如果传递的是对象,还将调用拷贝构造函数。
因此,当参数传递的数据较大时,用引用比用一般变量传递参数的效率和所占空间都好。
〔3〕使用指针作为函数的参数虽然也能到达与使用引用的效果,但是,在被调函数中同样要给形参分配存储单元,且需要重复使用"*指针变量名"的形式进展运算,这很容易产生错误且程序的阅读性较差;另一方面,在主调函数的调用点处,必须用变量的地址作为实参。
而引用更容易使用,更清晰。
4. 在什么时候需要使用“常引用〞?如果既要利用引用提高程序的效率,又要保护传递给函数的数据不在函数中被改变,就应使用常引用。
常引用声明方式:const 类型标识符&引用名=目标变量名;例1int a ;const int &ra=a;ra=1; //错误a=1; //正确例2string foo( );void bar(string & s);那么下面的表达式将是非法的:bar(foo( ));bar("hello world");原因在于foo( )和"hello world"串都会产生一个临时对象,而在C++中,这些临时对象都是const类型的。
因此上面的表达式就是试图将一个const类型的对象转换为非const类型,这是非法的。
引用型参数应该在能被定义为const的情况下,尽量定义为const 。
5. 将“引用〞作为函数返回值类型的格式、好处和需要遵守的规那么?格式:类型标识符&函数名〔形参列表及类型说明〕{ //函数体}好处:在内存中不产生被返回值的副本;〔注意:正是因为这点原因,所以返回一个局部变量的引用是不可取的。
因为随着该局部变量生存期的完毕,相应的引用也会失效,产生runtime error!考前须知:〔1〕不能返回局部变量的引用。
这条可以参照Effective C++[1]的Item 31。
主要原因是局部变量会在函数返回后被销毁,因此被返回的引用就成为了"无所指"的引用,程序会进入未知状态。
〔2〕不能返回函数内部new分配的内存的引用。
这条可以参照Effective C++[1]的Item 31。
虽然不存在局部变量的被动销毁问题,可对于这种情况〔返回函数内部new分配内存的引用〕,又面临其它为难局面。
例如,被函数返回的引用只是作为一个临时变量出现,而没有被赋予一个实际的变量,那么这个引用所指向的空间〔由new分配〕就无法释放,造成memory leak。
〔3〕可以返回类成员的引用,但最好是const。
这条原那么可以参照Effective C++[1]的Item 30。
主要原因是当对象的属性是与某种业务规那么〔business rule〕相关联的时候,其赋值常常与某些其它属性或者对象的状态有关,因此有必要将赋值操作封装在一个业务规那么当中。
如果其它对象可以获得该属性的非常量引用〔或指针〕,那么对该属性的单纯赋值就会破坏业务规那么的完整性。
〔4〕流操作符重载返回值申明为“引用〞的作用:流操作符<<和>>,这两个操作符常常希望被连续使用,例如:cout << "hello" << endl;因此这两个操作符的返回值应该是一个仍然支持这两个操作符的流引用。
可选的其它方案包括:返回一个流对象和返回一个流对象指针。
但是对于返回一个流对象,程序必须重新〔拷贝〕构造一个新的流对象,也就是说,连续的两个<<操作符实际上是针对不同对象的!这无法让人承受。
对于返回一个流指针那么不能连续使用<<操作符。
因此,返回一个流对象引用是惟一选择。
这个唯一选择很关键,它说明了引用的重要性以及无可替代性,也许这就是C++语言中引入引用这个概念的原因吧。
赋值操作符=。
这个操作符象流操作符一样,是可以连续使用的,例如:x = j = 10;或者(x=10)=100;赋值操作符的返回值必须是一个左值,以便可以被继续赋值。
因此引用成了这个操作符的惟一返回值选择。
例3#i nclude <iostream.h>int &put(int n);int vals[10];int error=-1;void main(){put(0)=10; //以put(0)函数值作为左值,等价于vals[0]=10;put(9)=20; //以put(9)函数值作为左值,等价于vals[9]=20;cout<<vals[0];cout<<vals[9];}int &put(int n){if (n>=0 && n<=9 ) return vals[n];else { cout<<"subscript error"; return error; }}〔5〕在另外的一些操作符中,却千万不能返回引用:+-*/ 四那么运算符。
它们不能返回引用,Effective C++[1]的Item23详细的讨论了这个问题。
主要原因是这四个操作符没有side effect,因此,它们必须构造一个对象作为返回值,可选的方案包括:返回一个对象、返回一个局部变量的引用,返回一个new分配的对象的引用、返回一个静态对象引用。
根据前面提到的引用作为返回值的三个规那么,第2、3两个方案都被否决了。
静态对象的引用又因为((a+b) == (c+d))会永远为true而导致错误。
所以可选的只剩下返回一个对象了。
6. “引用〞与多态的关系?引用是除指针外另一个可以产生多态效果的手段。
这意味着,一个基类的引用可以指向它的派生类实例。
例4Class A; Class B : Class A{...}; B b; A& ref = b;7. “引用〞与指针的区别是什么?指针通过某个指针变量指向一个对象后,对它所指向的变量间接操作。
程序中使用指针,程序的可读性差;而引用本身就是目标变量的别名,对引用的操作就是对目标变量的操作。
此外,就是上面提到的对函数传ref和pointer的区别。
8. 什么时候需要“引用〞?流操作符<<和>>、赋值操作符=的返回值、拷贝构造函数的参数、赋值操作符=的参数、其它情况都推荐使用引用。
以上2-8 参考: :///wfwd/archive/2006/05/30/763551.aspx9. 构造与联合有和区别?1. 构造和联合都是由多个不同的数据类型成员组成, 但在任何同一时刻, 联合中只存放了一个被选中的成员〔所有成员共用一块地址空间〕, 而构造的所有成员都存在〔不同成员的存放地址不同〕。
2. 对于联合的不同成员赋值, 将会对其它成员重写, 原来成员的值就不存在了, 而对于构造的不同成员赋值是互不影响的。
10. 下面关于“联合〞的题目的输出?a)#i nclude <stdio.h>union{int i;char x[2];}a;void main(){a.x[0] = 10;a.x[1] = 1;printf("%d",a.i);}答案:266 (低位低地址,高位高地址,内存占用情况是Ox010A〕b)main(){union{ /*定义一个联合*/int i;struct{ /*在联合中定义一个构造*/char first;char second;}half;}number;number.i=0x4241; /*联合成员赋值*/printf("%c%c\n", number.half.first, mumber.half.second);number.half.first='a'; /*联合中构造成员赋值*/number.half.second='b';printf("%x\n", number.i);getch();}答案:AB (0x41对应'A',是低位;Ox42对应'B',是高位〕6261 (number.i和number.half共用一块地址空间〕11. strcpy的函数原型:char *strcpy(char *strDest, const char *strSrc)其中strDest 是目的字符串,strSrc 是源字符串。
不调用C++/C 的字符串库函数,请编写函数strcpy。
答案:char *strcpy(char *strDest, const char *strSrc){if ( strDest == NULL || strSrc == NULL)return NULL ;if ( strDest == strSrc)return strDest ;char *tempptr = strDest ;while( (*strDest++ = *strSrc++) != ‘\0’);return tempptr ;}12. String类定义如下:class String{public:String(const char *str = NULL); // 通用构造函数String(const String &another); // 拷贝构造函数~ String(); // 析构函数String & operater =(const String &rhs); // 赋值函数private:char *m_data; // 用于保存字符串};尝试写出类的成员函数实现。