1、面试题目笔试面试题整理,慢慢搜集现在的公司招聘,都要笔试面试.如果你不是那种编程功底非常深厚的人,又不好好准备一番,在笔试面试中往往会处于被动局面.虽然有些笔试题是故意为难我们,有点钻牛角尖.但是很多笔试题面试题确实能够很好地看出我们的基础. 在这里,我就略去那些钻牛角尖的题.从csdn论坛我近半年的收集中选出10道有代表性的题目,难度基本上是逐渐加大.对数组,指针,数据结构,算法,字符串,文件操作等问题都有覆盖.主要以c语言的实现为主,也有c+的题.大家可以先做做这10道题,测试一下自己的水平.1. 下面这段代码的输出是多少(在32位机上). char *p; char *q20; char
2、 *m2020; int (*n)10; struct MyStruct char dda; double dda1; int type ;; MyStruct k;printf(%d %d %d %d,sizeof(p),sizeof(q),sizeof(m),sizeof(n),sizeof(k);2.(1)char a223=1,6,3,5,4,15,3,5,33,23,12,7 ;for(int i=0;i6)?puts(6):puts(6就是考察隐式转换int型变量转化成unsigned int,b成了正数2. b)运行下面的函数会有什么结果?为什么? void foo(void)
3、char string10,str110; int i; for(i=0;i10;i+) str1i = a; strcpy(string, str1); printf(%s,string); 首先搞清strcpy函数的实现方法,char * strcpy(char * strDest,const char * strSrc)if (strDest=NULL)|(strSrc=NULL)throw Invalid argument(s);char * strDestCopy=strDest;while (*strDest+=*strSrc+)!=0);return strDestCopy;由于
4、str1末尾没有0结束标志,所以strcpy不知道拷贝到何时结束printf函数,对于输出char* 类型,顺序打印字符串中的字符直到遇到空字符()或已打印了由精度指定的字符数为止下面是微软的两道笔试题.3. Implement a string class in C+ with basic functionality like comparison, concatenation, input and output. Please also provide some test cases and using scenarios (sample code of using this class)
5、.Please do not use MFC, STL and other libraries in your implementation.我的实现方案如下,这道题真地对c+的主要特性都进行了较好地考察.String.h:#ifndef STRING_H#define STRING_H#include using namespace std;class String public: String(); String(int n,char c); String(const char* source); String(const String& s); /String& operator=(ch
6、ar* s); String& operator=(const String& s); String(); char& operator(int i)return ai; const char& operator(int i) const return ai;/对常量的索引. String& operator+=(const String& s); int length(); friend istream& operator(istream& is, String& s);/搞清为什么将设置为友元函数的原因. /friend bool operator (const String& left,
7、 const String& right);/下面三个运算符都没必要设成友元函数,这里是为了简单. friend bool operator= (const String& left, const String& right); friend bool operator!= (const String& left, const String& right); private: char* a; int size;#endifString.cpp:#include String.h#include #include String:String() a = new char1; a0 = 0; s
8、ize = 0;String:String(int n,char c)a = new charn + 1;memset(a,c,n);an = 0;size = n;String:String(const char* source)if(source = NULL)a = new char1;a0 = 0;size = 0;else size = strlen(source);a = new charsize + 1;strcpy(a,source);String:String(const String& s)size = strlen(s.a);/可以访问私有变量.a = new chars
9、ize + 1;/if(a = NULL)strcpy(a,s.a);String& String:operator=(const String& s)if(this = &s)return *this;elsedelete a; size = strlen(s.a);a = new charsize + 1;strcpy(a,s.a);return *this;String:String()delete a;/ String& String:operator+=(const String& s) int j = strlen(a); int size = j + strlen(s.a); c
10、har* tmp = new charsize+1; strcpy(tmp,a); strcpy(tmp+j,s.a);delete a;a = tmp;return *this;int String:length()return strlen(a);main.cpp:#include #include String.husing namespace std;bool operator=(const String& left, const String& right)int a = strcmp(left.a,right.a); if(a = 0)return true;elsereturn
11、false;bool operator!=(const String& left, const String& right)return !(left = right);ostream& operator(ostream& os,String& s)int length = s.length();for(int i = 0;i length;i+)/os s.ai;这么不行,私有变量.os si;return os;String operator+(const String& a,const String& b)String temp;temp = a;temp += b;return tem
12、p;bool operator(const String& left,const String& right)int j = 0;while(leftj != 0) & (rightj != 0)if(leftj (const String& left, const String& right) int a = strcmp(left.a,right.a); if(a 0)return true;elsereturn false;istream& operator(istream& is, String& s)delete s.a;s.a = new char20;int m = 20; ch
13、ar c;int i = 0;while (is.get(c) & isspace(c); if (is) dos.ai = c; i+; /*if(i = 20) cout Input too much characters! f;/需要输入.String g;g = a + b;/abcdwwwif(a b)cout a b endl;elsecout = b endl;if(e = a)cout e = a endl;elsecout e != a endl;b += a;cout a endl;cout b endl; cout c endl;cout d endl;cout e en
14、dl;cout f endl;cout g endl;cout g0 endl;return 0;4. Implement a single-direction linked list sorting algorithm. Please first define the data structure of linked list and then implement the sorting algorithm. 5.编写一个函数,返回两个字符串的最大公串!例如,“adbccadebbca”和“edabccadece”,返回“ccade”联想笔试题1设计函数 int atoi(char *s)。
15、int atoi(const char *nptr);函数说明atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再 遇到非数字或字符串结束时(0)才结束转换,并将结果返回。返回值 返回转换后的整型数。#include #include int myAtoi(const char* s)int result = 0;int flag = 1;int i = 0;while(isspace(si)i+;if(si = -)flag = -1;i+;if(si = +)i+;while(si != 0)if(si 9) | (si 0)break;int
16、 j = si - 0;result = 10 * result + j;i+;result = result * flag;return result;int main()char* a = -1234def;char* b = +1234;int i = myAtoi(a);int j = myAtoi(b);printf(%d n,i);printf(%d,j);return 0;2int i=(j=4,k=8,l=16,m=32); printf(“%d”, i); 输出是多少?3解释局部变量、全局变量和静态变量的含义。4解释堆和栈的区别。5论述含参数的宏与函数的优缺点。普天C+笔试题
17、1实现双向链表删除一个节点P,在节点P后插入一个节点,写出这两个函数。2写一个函数,将其中的t都转换成4个空格。3Windows程序的入口是哪里?写出Windows消息机制的流程。4如何定义和实现一个类的成员函数为回调函数?5C+里面是不是所有的动作都是main()引起的?如果不是,请举例。6C+里面如何声明const void f(void)函数为C程序中的库函数?7下列哪两个是等同的int b;A const int* a = &b;B const* int a = &b;C const int* const a = &b;D int const* const a = &b;8内联函数在编
18、译时是否做参数类型检查?void g(base & b) b.play;void main() son s; g(s); return;华为笔试题1请你分别画出OSI的七层网络结构图和TCP/IP的五层结构图。2请你详细地解释一下IP协议的定义,在哪个层上面?主要有什么作用?TCP与UDP呢?3请问交换机和路由器各自的实现原理是什么?分别在哪个层次上面实现的?4请问C+的类和C里面的struct有什么区别?5请讲一讲析构函数和虚函数的用法和作用。6全局变量和局部变量有什么区别?是怎么实现的?操作系统和编译器是怎么知道的?78086是多少位的系统?在数据总线上是怎么实现的?Sony笔试题1完成下
19、列程序*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.#include #define N 8int main() int i; int j; int k; - | | | | | | - return 0;2完成程序,实现对数组的降序排序#include void sort( );int main() int array=45,56,76,234,1,34,23,2,3; /数字任/意给出 sort( ); return 0;void sort( ) _ | | | | |-|3费波那其数列,1,1,2,3,5编写程序求第十项。可以用递归,也可以
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1