C/C++笔试题(10)

来源:互联网 发布:知安科技 编辑:程序博客网 时间:2024/06/18 03:12
 戴尔


  I.Choose one question and write down the trouble shooting steps in English ( 4-5 steps )
    
1.Customer report his computer cannot start after sudden power lost. How will you trouble shoot and find out the cause of the failure.
    
2.One computer was used normally last day, but today, the user cannot connect to internet via dial-up networking.
    
3.Customer complain the system send out great noise. What’s the detail action to identify the faulty part?
    
4.My computer was suddenly disconnected from LAN, how to trouble shoot?
    
5.My computer was hung up. After reboot, only one cursor blinked on the upper-left corner. How to fix this problem.
  
II. Reading and translation:
    
Passage 1.
    
Customer called in and reported the battery weren’t charging, System LED indicator was in yellow.
    
1.Suggested customer remove the battery from the battery bay by sliding the latch at the bottom of Notebook. Checked the battery power level by pressing the check button on the battery. It indicated no power.
    
2.Suggested customer remove the CD ROM off the Media bay, then plug the Battery to the media bay, it was still same result.
    
3.Suggested customer try with other battery, in the battery bay and media bay, it was ok. Battery could be charged.
    
4.Requested customer provide the DSN number from the fail battery. CN-05H980-69502-21U-01GB.
    

    Informed customer that we would send a replaced battery to her.
    
Passage 2.
    
Customer bought a Notebook 20 day ago, then discovered that when she adjusted the Brightness of the LCD, the LCD would turn to very dim. She must reboot the Notebook few times before the LCD might display normally.
    
1.Suggested her try gently apply pressure above the keyboard near the LEDS and power button.
    
2.Suggested her swivel the LCD back and forth and lightly tap the plastic back of LCD.
    
3.Suggested her gently apply pressure on the bezel surrounding the screen. the problem persisted, after these testing.
    
4.Requested customer to update BIOS and alter the LCD Brightness control setting in the BIOS. After checking BIOS the problem persisted.
    
I told customer we would have engineer onsite replace the LCD Panel.
    
Computer communications
    
Different kinds of computers use different methods, or protocols, to communicate with each other. Macintosh computers use the AppleTalk protocol. Macintosh as well as PCs can use TCP/IP to share information on the Internet. Some PCs require a Network Operating System (NOS) to communicate. For example, Novell Netware is a popular NOS with PC users.
  


意法半导体软件试题


  A Test for The C Programming Language
  
I. History
  
1. C was originally designed for and implemented on the (what) operating system on the DEC PDP-11, by (who) .
  
2. The most recently approved ANSI/ISO C standard was issued in (when) , and single line comments notation “//” is or isn’t a feature of C89.
  
II. Syntax and Semantics
  
1. In a runtime C program, auto variables are stored in , static variables are stored in , and function parameters are stored in .
  
a. stack b. heap c. neither stack nor heap
  
2. The statement “extern int x;” is a , and the keyword extern is used during .
  
a. variable declaration b. variable definition
  
c. compilation time d. runtime
  
3. There is a complicated declaration: void ( * signal (int, void (*)(int)) ) (int);
  
If a statement “typedef void (*p) (int);” is given, please rewrite this complicated declaration.
  
4. The following code is a segment of C program.
  
..........
  
void func(int *p)
  
{...........}
  
..........
  
main()
  
{
  
int num=0;
  
.........
  
func(&num);
  
........
  
}
  
..........
  
Here, the function argument “&num” is passed .
  
a. by value b. by reference
  
III. Practice
  
Create a tree, which has h (h>0) layers, and its each node has w (w>0) sub-nodes.
  
Please complete the following incomplete solution.
  
#include <stdlib.h>
  
#include <string.h>
  
struct tree{
  
char info;
  
p_sub; //link to sub-nodes
  
};
  
// allocate memory and initiate
  
void dnode ( struct tree* tmp )
  
{
  
= malloc( sizeof (struct tree) );
  
= 0x41;
  
= NULL;
  
}
  
struct tree *dtree (struct tree* subtree, int height, int width)
  
{
  
int i;
  
if ( !subtree ) //if necessary, allocte memory for subtree
  
denode(subtree);
  
if ( height == 1 )
  
return subtree;
  
else if ( height == 2 ) {
  
struct tree *leaf = NULL;
  

   for ( i=0; i<width; i++ ) {
  
denode ( );
  
;
  
leaf = NULL;
  
}
  

   return subtree;
  
}
  
else {
  

   for ( i=0; i<width; i++ ) {
  

   }
  

   return subtree;
  
}
  
}
  
main()
  
{
  
.........
  
struct tree *root = NULL;
  
root = dtree (root, h, w) ; // h and w are integers get from input
  
.........
  
}
  

 华为笔试题


1.请你分别画出OSI的七层网络结构图和TCP/IP的五层结构图。

7 应用层         5应用层
6
表示层         4传输层
5
会话层         3 网络层
4
传输层         2 数据链路层
3
网络层         1物理层
2
数据链路层    

1 物理层


  2.请你详细地解释一下IP协议的定义,在哪个层上面?主要有什么作用?TCPUDP呢?

IP协议(Internet Protocol)又称互联网协议,是支持网间互连的数据报协议,它与TCP协议(传输控制协议)一起构成了TCP/IP协议族的核心。

 

3.请问交换机和路由器各自的实现原理是什么?分别在哪个层次上面实现的?

交换机(二层交换)的工作原理和网桥一样,它的各个端口都具有桥接功能,每个端口可以连接一个LAN或一台高性能网站或服务器,交换机按每一个包中的MAC地址相对简单地决策信息转发。//路由器转发IP分组时,只根据IP分组目的IP地址的网络号部分,选择合适的端口,把IP分组送出去。同主机一样,路由器也要判定端口所接的是否是目的子网,如果是,就直接把分组通过端口送到网络上,否则,也要选择下一个路由器来传送分组。

交换机一般用于LAN-WAN的连接,交换机归于网桥,是数据链路层的设备,有些交换机也可实现第三层的交换。路由器用于WAN-WAN之间的连接,可以解决异性网络之间转发分组,作用于网络层。


  4.请问C++的类和C里面的struct有什么区别?


  5.请讲一讲析构函数和虚函数的用法和作用。

答:析构函数是在对象生存期结束时自动调用的函数,用来释放在构造函数分配的内存。
虚函数是指被关键字virtual说明的函数,作用是使用C++语言的多态特性


  6.全局变量和局部变量有什么区别?是怎么实现的?操作系统和编译器是怎么知道的?

答:一些变量在整个程序中都是可见的,它们称为全局变量。一些变量只能在一个函数中可知,称为局部变量。这就是他们的区别。在任何函数外面定义的变量就是全局变量,在函数内部定义的变量是局部变量,这是它们在程序中的实现过程。操作系统和编译器是根据程序运行的内存区域知道他们的,程序的全局数据放在所分配内存的全局数据区,程序的局部数据放在栈区。

 

78086是多少位的系统?在数据总线上是怎么实现的?
  *808616微处理器,内部及对外有16位数据通路,8080/8085只有8位。    8086寻址空间1MB,8080/808564KB8086有一个初级流水线结构,内部操作与对外操作具有并行性,8085无。 8086是个里程碑。
8086
的机器字长是16位,8086使用40个引脚的16个做地址/数据复用引腿来传输数据,一次读写过程由一个基本总线周期完成,它由4个时钟(CLK)周期组成,按时间顺序定义为T1T2T3T4。在T1期间8086发出访问目的地的地址信号和地址锁存选通信号ALET2期间发出读写命令信号RDWR及其它相关信号;T3期间完成数据的访问;T4结束该总线周期。可见,地址与数据信号不会同时出现在一个时钟(CLK)周期,二者可以分时复用同一组引线。

 

 

华为


1
、局部变量能否和全局变量重名?
答:能,局部会屏蔽全局。要用全局变量,需要使用"::"
局部变量可以与全局变量同名,在函数内引用这个变量时,会用到同名的局部变量,而不会用到全局变量。对于有些编译器而言,在同一个函数内可以定义多个同名的局部变量,比如在两个循环体内都定义一个同名的局部变量,而那个局部变量的作用域就在那个循环体内


2、如何引用一个已经定义过的全局变量?
答:extern
可以用引用头文件的方式,也可以用extern关键字,如果用引用头文件方式来引用某个在头文件中声明的全局变理,假定你将那个变写错了,那么在编译期间会报错,如果你用extern方式引用时,假定你犯了同样的错误,那么在编译期间不会报错,而在连接期间报错


3、全局变量可不可以定义在可被多个.C文件包含的头文件中?为什么?
答:可以,在不同的C文件中以static形式来声明同名全局变量。可以在不同的C文件中声明同名的全局变量,前提是其中只能有一个C文件中对此变量赋初值,此时连接不会出错


4、语句for( 1 )有什么问题?它是什么意思?
答:和while(1)相同。


5
do……whilewhile……do有什么区别?
答:前一个循环一遍再判断,后一个判断以后再循环


6、请写出下列代码的输出内容
#include<stdio.h>
main()
{
int a,b,c,d;
a=10;
b=a++;
c=++a;
d=10*a++;
printf("b
cd%d%d%d"bcd;
return 0;
}
答:1012
120

1
static全局变量与普通的全局变量有什么区别?static局部变量和普通局部变量有什么区别?static函数与普通函数有什么区别?
析:全局变量(外部变量)的说明之前再冠以static 就构成了静态的全局变量。全局变量本身就是静态存储方式, 静态全局变量当然也是静态存储方式 这两者在存储方式上并无不同。这两者的区别虽在于非静态全局变量的作用域是整个源程序, 当一个源程序由多个源文件组成时,非静态的全局变量在各个源文件中都是有效的。 而静态全局变量则限制了其作用域, 即只在定义该变量的源文件内有效, 在同一源程序的其它源文件中不能使用它。由于静态全局变量的作用域局限于一个源文件内,只能为该源文件内的函数公用, 因此可以避免在其它源文件中引起错误。
从以上分析可以看出, 把局部变量改变为静态变量后是改变了它的存储方式即改变了它的生存期。把全局变量改变为静态变量后是改变了它的作用域, 限制了它的使用范围。
static
函数与普通函数作用域不同。仅在本文件。只在当前源文件中使用的函数应该说明为内部函数(static),内部函数应该在当前源文件中说明和定义。对于可在当前源文件以外使用的函数,应该在一个头文件中说明,要使用这些函数的源文件要包含这个头文件

答:static全局变量与普通全局变量区别:static全局变量只初使化一次,防止在其他文件单元中被引用;
static
局部变量和普通局部变量区别:static局部变量只被初始化一次,下一次依据上一次结果值;

static函数与普通函数区别:static函数在内存中只有一份,普通函数在每个被调用中维持一份拷贝


2、程序的局部变量存在于(堆栈)中,全局变量存在于(静态区 中,动态申请数据存在于 堆)中。


3
、设有以下说明和定义:
typedef union {long i; int k[5]; char c;} DATE;
struct data { int cat; DATE cow; double dog;} too;
DATE max;
则语句 printf("%d",sizeof(struct date)+sizeof(max));的执行结果是:_______
答:DATE是一个union, 变量共用空间. 里面最大的变量类型是int[5], 占用20个字节. 所以它的大小是
20
data
是一个struct, 每个变量分开占用空间. 依次为
int4 + DATE20 + double8 = 32.
所以结果是
20 + 32 = 52.
当然...在某些16位编辑器下, int可能是2字节,那么结果是 int2 + DATE10 + double8 = 20


4
、队列和栈有什么区别?
队列先进先出,栈后进先出


5、写出下列代码的输出内容
#include<stdio.h>
int inc(int a)
{
return(++a);
}
int multi(int*a,int*b,int*c)
{
return(*c=*a**b);
}
typedef int(FUNC1)(int in);
typedef int(FUNC2) (int*,int*,int*);

void show(FUNC2 fun,int arg1, int*arg2)
{
INCp=&inc;
int temp =p(arg1);
fun(&temp,&arg1, arg2);
printf("%d/n",*arg2);
}

main()
{
int a;
show(multi,10,&a);
return 0;
}
答:110  ???

 

7、请找出下面代码中的所以错误
说明:以下代码是把一个字符串倒序,如“abcd”倒序后变为“dcba”
1
#include"string.h"
2
main()
3
{
4
char*src="hello,world";
5
char* dest=NULL;
6
int len=strlen(src);
7
dest=(char*)malloc(len);
8
char* d=dest;
9
char* s=src[len];
10
while(len--!=0)
11
d++=s--;
12
printf("%s",dest);
13
return 0;
14
}
答:

方法1
int main(){
char* src = "hello,world";
int len = strlen(src);
char* dest = (char*)malloc(len+1);//
要为/0分配一个空间
char* d = dest;
char* s = &src[len-1];//
指向最后一个字符
while( len-- != 0 )
*d++=*s--;
*d = 0;//
尾部要加/0
printf("%s/n",dest);
free(dest);//
使用完,应当释放空间,以免造成内存汇泄露

return 0;
}
方法2
#include <stdio.h>
#include <string.h>
main()
{
char str[]="hello,world";
int len=strlen(str);
char t;
for(int i=0; i<len/2; i++)
{
t=str[i];
str[i]=str[len-i-1]; str[len-i-1]=t;
}
printf("%s",str);
return 0;
}


2.用两个栈实现一个队列的功能?要求给出算法和思路!
2个栈为A,B, 一开始均为空.
入队
:
将新元素push入栈
A;
出队
:
(1)
判断栈B是否为空;

(2)
如果不为空,则将栈A中所有元素依次pop出并push到栈B
(3)
将栈B的栈顶元素pop出;

3.c语言库函数中将一个字符转换成整型的函数是atool()吗,这个函数的原型是什么?
函数名: atol
: 把字符串转换成长整型数

: long atol(const char *nptr);
程序例
:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
long l;
char *str = "98765432";
l = atol(lstr);
printf("string = %s integer = %ld/n", str, l);
return(0);
}

 

2.对于一个频繁使用的短小函数,C语言中应用什么实现,C++中应用什么实现?
c
用宏定义,c++inline


3.
直接链接两个信令点的一组链路称作什么?
PPP
点到点连接


4.
接入网用的是什么接口?


5.voip
都用了那些协议?

VOIP ,即指在 IP 网络上使用 IP 协议以数据包的方式传输语音。存在一些 VOIP 协议栈,如 H.323SIPMEGACO MGCP


6.
软件测试都有那些种类?
黑盒:针对系统功能的测试 白合:测试函数功能,各函数接口


7.
确定模块的功能和模块的接口是在软件设计的那个队段完成的?
概要设计阶段


8.enum string
{
x1,
x2,
x3=10,
x4,
x5,
}x;
x1=0, x2=0, x3=10, x4=11x5=12; 初始化时可以赋负数, 以后的标识符仍依次加1


9.unsigned char *p1;
unsigned long *p2;
p1=(unsigned char *)0x801000;
p2=(unsigned long *)0x810000;
请问p1+5= ;p2+5= ;

801005 810014。不要忘记了这个是16进制的数字,p2要加20变为16进制就是14


.选择题:
1.Ethternet
链接到Internet用到以下那个协议
?
A.HDLC;B.ARP;C.UDP;D.TCP;E.ID


2.
属于网络层协议的是:    B
A.TCP;B.IP;C.ICMP;D.X.25

OSI中的层 

功能                                    

TCP/IP协议族

应用层

 文件传输,电子邮件,文件服务,虚拟终端

TFTPHTTPSNMPFTPSMTPDNSTelnet

表示层

数据格式化,代码转换,数据加密 

没有协议

会话层

解除或建立与别的接点的联系

 没有协议

传输层

 提供端对端的接口   

 TCPUDP

网络层

为数据包选择路由   

  IPICMPRIPOSPFBGPIGMP

数据链路层 

 传输有地址的帧以及错误检测功能    

 SLIPCSLIPPPPARPRARPMTU

物理层

 以二进制数据形式在物理媒体上传输数据 

 ISO2110IEEE802IEEE802.2



 
3.Windows消息调度机制是:
A.
指令队列;B.指令堆栈;C.消息队列;D.消息堆栈;


4.unsigned short hash(unsigned short key)  
华为
{
return (key>>)%256
}
请问hash(16),hash(256)的值分别是
:
A.1.16;B.8.32;C.4.16;D.1.32


.找错题:
1.
请问下面程序有什么错误
?
int a[60][250][1000],i,j,k;
for(k=0;k<=1000;k++)
for(j=0;j<250;j++)
for(i=0;i<60;i++)
a[i][j][k]=0;
把循环语句内外换一下


2.#define Max_CB 500
void LmiQueryCSmd(Struct MSgCB * pmsg)
{
unsigned char ucCmdNum;
......

for(ucCmdNum=0;ucCmdNum<Max_CB;ucCmdNum++)
{
......;
}
死循环


3.
以下是求一个数的平方的程序,请找出错误:
#define SQUARE(a)((a)*(a))
int a=5;
int b;
b=SQUARE(a++);

预期结果是a=6,b=36.但是实际结果是a=7,b=25 实际是b=(a++)*(a++) a累加2


4.typedef unsigned char BYTE
int examply_fun(BYTE gt_len; BYTE *gt_code)
{
BYTE *gt_buf;
gt_buf=(BYTE *)MALLOC(Max_GT_Length);
......
if(gt_len>Max_GT_Length)
{
return GT_Length_ERROR;
}
.......
}


.问答题:
1.IP Phone
的原理是什么
?
IPV6


2.TCP/IP
通信建立的过程怎样,端口有什么作用?
三次握手

A->B SYN:我的初始序号是XACK0,设置SYN位,未设置ACK位。
B->A ACK
:你的序号是X+1,我的初始序号是Y,设置SYN位和ACK位。

A->B ACK:你的序号是Y+1,我的序号是X+1,设置ACK位,未设置SYN位;

端口确定是哪个应用程序使用该协议


3.1
号信令和7号信令有什么区别,我国某前广泛使用的是那一种?

1号信令利用TS16传送时,每个TS16负责传送两个话路的线路信令,TS16和话路有着固定的一一对应关系。而7号信令利用TS16来传送时,只是将组成信令单元的若干个8位位组,依次插入TS16TS16并不知道传送的内容,即信令和话路没有固定关系,只不过利用TS16作为传送信令的载体,时传送信令消息的数据链路,因此,选用哪个时隙做数据链路均可。 --- 这也是随路信令和公共信道信令的一个本质区别。我国目前广泛使用的是7号信令。


4.
列举5种以上的电话新业务?

华为全套完整试题


高级题
6
、已知一个单向链表的头,请写出删除其某一个结点的算法,要求,先找到此结点,然后删除。
slnodetype *Delete(slnodetype *Head,int key){}
if(Head->number==key)
{
Head=Pointer->next;
free(Pointer);
break;
}
Back = Pointer;
Pointer=Pointer->next;
if(Pointer->number==key)
{
Back->next=Pointer->next;
free(Pointer);
break;
}
void delete(Node* p)
{
if(Head = Node)
while(p)
}

有一个16位的整数,每4位为一个数,写函数求他们的和。
解释:整数1101010110110111
     
1101+0101+1011+0111
答案:用十进制做参数,计算时按二进制考虑。

/* n
就是16位的数,函数返回它的四个部分之和 */
char SumOfQuaters(unsigned short n)
{
char c = 0;
int i = 4;
do
{
c += n & 15;
n = n >> 4;
} while (--i);

return c;
}

1,2,....一直到n的无序数组,求排序算法,并且要求时间复杂度为O(n),空间复杂度O(1),使用交换,而且一次只能交换两个数.(华为)

#include<iostream.h>

int main()
{
int a[] = {10,6,9,5,2,8,4,7,1,3};
int len = sizeof(a) / sizeof(int);
int temp;

for(int i = 0; i < len; )
{
temp = a[a[i] - 1];
a[a[i] - 1] = a[i];
a[i] = temp;

if ( a[i] == i + 1)
i++;

}
for (int j = 0; j < len; j++)
cout<<a[j]<<",";

return 0;
}