Summary of written questions for large companies (1)--46 Questions

Source: Internet
Author: User
Tags switches

In order to find a work sprint next month, I have seen the written questions answered and posted here, I hope for all people are helpful. This article's code all is the personal compilation, and all in the VC + + 6.0 development environment passes the test, please rest assured uses. At the same time reprint, please indicate the source. If there is a better algorithm to achieve, welcome guidance.

This chapter mainly refers to the network more popular "46 Home pen question answer", need to download the original title can be found in the following links: http://download.csdn.net/source/1671590 A, sony company Pen Test

1. Print the following information
*
*.*.
*.. *.. *..
*...*...*...*...
*....*....*....*....*....
*.....*.....*.....*.....*.....*.....
*......*......*......*......*......*......*......
*.......*.......*.......*.......*.......*.......*.......*.......

#include <stdio.h> #define N 8 int main () {int i,j,k; i=0;i<n;i++) {for (j=0;j<=i;j++) {printf ("*"); k=0;k<i;k++) {printf (".");}} printf ("n"); return 0; }

2, give the following array of reverse order: int array[]={45,56,76,234,1,34,23,2,3}

#include <stdio.h> void sort (); void print ()//is the function int array[]={45,56,76,234,1,34,23,2,3} that is appended to me; int main () {sort (); print (); return 0;} void sort () {for (int j=0;j<9;j++) {int mid_value; int min_value=array[j]; f or (int i=0;i<9;i++) {if (Array[i]<min_value) {mid_value=array[i]; array[i]=min_value; min_value=mid_value;}} Array[j]=min_value; } void Print () {for (int i=0;i<9;i++) {printf ("%d", Array[i]);}

3. Fibonacci that its series, 1,1,2,3,5 ... Write a program to find the tenth item. You can use recursion or other methods, but explain the reasons you choose.

#include <stdio.h> int pheponatch (int); int main () {printf ("The 10th is%d", pheponatch); printf ("n"); return 0;} int pheponatch (int n) {if (n==1) | | (n==2)) {return 1;} else return (Pheponatch (N-1) +pheponatch (N-2)); }

4. The following programs crash when they run, identify the errors and correct them, and explain why.

Note: Because the test environment is vc++6.0, the grammar of the original problem has been modified.

#include <stdio.h> #include <malloc.h> typedef struct node{struct node* left; struct node* right; int value; } tnode; tnode* Root=null; void append (int N); int main () {append (), append (), append (), append (), append (), append (), append (a);//Again, number free return 0 ; } void Append (int N) {tnode* newnode= (tnode *) malloc (sizeof (tnode)); newnode->value=n; if (root==null) {root=newnode; return} else {tnode* temp. temp=root; while (N>=temp->value && Temp->le Ft!=null) | | (N<temp->value && temp->right!=null)) {while (N>=temp->value && temp->left!=null) temp=temp->left; while (N<temp->value & & Temp->right!=null) temp=temp->right; } if (N>=temp->value) temp->left=newnode; else temp->right=newnode; Return } }

The error is that the struct needs to clear zero before it is used, otherwise the runtime crashes. The modified part of the code is as follows:

tnode* newnode= (Tnode *) malloc (sizeof (tnode)); newnode->value=n; newnode->left=null; newnode->right=null; second, Huawei Company Pen Test

1, please draw the OSI seven-layer network structure diagram and TCP/IP five-layer structure.
7 Application Layer 5 Application Layer
6 Expression Layer 4 Transport layer
5 Session Layer 3 Network layer
4 Transport Layer 2 data link layer
3 Network layer 1 physical layer
2 Data Link Layer
1 Physical Layer

2. Please explain in detail what layer the IP protocol is defined on. What is the main role. What about TCP and UDP?

IP protocol (Internet Protocol), also known as Internet Protocol, is a datagram protocol that supports interconnection between networks, and it forms the core of TCP/IP protocol family together with TCP protocol (transmission protocol). It's on the network layer. It is used primarily for routing packets and addressing between hosts.

TCP and UDP protocols at the transport level.

3. What is the principle of the switch and router's respective implementation? At which level each is implemented.

Switch (two-tier switching) works like a network bridge, its ports have bridging function, each port can connect a LAN or a high-performance Web site or server, the switch in each packet of MAC address relatively simple decision information forwarding. Router forwarding IP packet, only based on IP packet destination IP address of the network number part, select the appropriate port, the IP packet sent out. Like the host, the router should also determine whether the port is connected to the destination subnet, if it is, directly to the packet through the port to the network, otherwise, also choose the next router to transfer the group.
Switches are generally used for lan-wan connections, switches to Network Bridge, data link layer equipment, some switches can also achieve the third layer of exchange. Routers are used for connections between Lan-wan, which can be used to resolve the forwarding groupings between opposite-sex networks, and to use the network layer.

4, please ask C + + class and C inside the struct what is the difference.

(1) The default access type for properties in the C + + class is private, and struct in C has no access type
(2) C + + classes can have inheritance, virtual functions, polymorphism, and C struct not.
(3) C language struct inside can not have functions, can only have variables. C + + extends the struct function in C

5, please tell me about the use and function of the destructor and virtual function.

(1) destructor is a special class member function, it has no return type, no parameters, can not be arbitrarily invoked, there is no overload, only at the end of the life of the class object, by the system automatically called. The main purpose is to automatically obtain resources, you can complete the required resource recovery, as a complement to the class constructor.

How to use: In the definition of the time with the ~ logo can be.
(2) A virtual function is a manifestation of C + + polymorphism: For example, a subclass inherits a function (method) of the parent class, and when we point the pointer to a subclass, the parent class must have the function (method) set to virtual (virtual function). Using virtual functions, we are flexible to dynamically bind, of course, at the expense of a certain cost.

How to: Use the virtual keyword.

6. What is the difference between a global variable and a local variable? How it is achieved. How does the operating system and compiler know?

The difference between a global variable and a local variable is that the location is different in the memory, in particular, the global variables are stored in the data segment, local variables are possible, generally in the stack segment; The compiler is judged by the syntax. The operating system can be judged by the storage location.

7, 8086 is how many bits of the system. How it is implemented on the data bus.

8086 is 16 microprocessor, internal and external 16-digit data access, 8080/8085 only 8 bits. 8086 addressable space 1mb,8080/8085 is 64KB. 8086 has a primary pipeline structure, internal operations and external operations with parallelism, 8085 without. 8086 is a milestone.
8086 of the machine word length is 16 bits, 8086 use 40 pin 16 to do address/data multiplexing pin to transmit data, a read-write process is completed by a basic bus cycle, which consists of 4 clock (CLK) cycle, defined as T1, T2, T3, T4. A read and write command Signal Rd, WR and other related signals are issued during the T1 period of 8086 address signal and address-lock-selection communication number ALE;T2 the access destination; Access to the data is completed during T3; T4 ends the bus cycle.  It can be seen that the address and data signals do not appear at the same time in a clock (CLK) cycle, and they may be reused for the same set of leads. third, Lenovo company Pen Test

1, design function int atoi (char *s): string converted to number

#include <stdio.h> #include <ctype.h> int atoi (char*); int main () {char * s=, printf ("%d/n", Atoi (s)), return 0; int atoi (char s[)) {int i,n,sign; for (I=0;isspace (s[i)); i++)//skip blank characters; sign= (s[i]== '-')? -1:1; if (s[i]== ' + ' | | s[i]== '-')//skip symbol i++; For (N=0;isdigit (s[i)); i++ n=10*n+ (s[i]-' 0 ');//convert numeric characters to shaping numbers return sign *n; }

2, int i= (J=4,K=8,L=16,M=32); printf ("%d", I); The output is how much.

32, the comma expression takes the last value, which is similar to int i=32;

3, explain the meaning of local variables, global variables and static variables. (1) Local variables: variables defined within a function are internal variables that are valid only in the scope of this function, that is, they can be used only within this function and cannot be used outside of this function, which is called local variables;
Description
1. Variables defined in main function main are also valid only in the main function, not because they are defined in the main function and are valid throughout the file or program
2. Variables with the same name can be used in different functions, they represent different objects and do not interfere with each other
3. The form parameter also makes the local variable
4. Within a function, you can define variables within a compound statement that are valid only in this conformance statement
(2) Global variables: variables defined outside the function are external variables, external variables are global variables, global variables can be shared by other functions in this file, its effective range from the location of the definition variable to the source file end;
Description
1. Set the role of global variables: To increase the data link between functions channels
2. It is recommended that you do not use global variables when they are no longer necessary, because a. Global variables occupy the storage unit during the full execution of the program; b. It reduces the versatility of the function by C. Using too many global variables reduces the clarity of the program
3. If the external variable is defined at the beginning of the file, the external variable can be used throughout the file scope and, if no longer defined at the beginning of the file, the scope is limited to the end of the file by the definition point. If the function before the definition point wants to refer to the external variable, you should use the keyword extern as an external variable description in the function
4. If the external variable has the same name as a local variable in the same source file, the external variable does not work within the scope of the local variable;
(3) Static variable: A variable that allocates a fixed storage space during program operation, called a static variable. 4. Explain the difference between heap and stack. Memory allocated on the stack, automatically allocated by the system, the system will automatically retract.
If you need to allocate memory dynamically, you can only allocate memory through malloc/new on the heap.
After use, the memory is freed by Free/delete. 5, discuss the advantages and disadvantages of macros and functions with parameters. Macro Benefits with Parameters: eliminates the overhead of function calls, and runs high efficiency.
Disadvantages with parameters: Because macros are essentially substitutions of strings, all may be caused by side effects of some parameters
The result of the error. such as: #define MAX (A, B) (((a) > (b))? (a): (b))
If such a call occurs in a program: Max (a++, b);
Will cause a to be computed 2 times, which may result in incorrect results, which do not occur with function calls. In addition, if you have multiple macro substitutions in your program, the code may become larger. The advantage of a function is that there is no side effect that can be caused by a macro with parameters, and the correctness of the calculation is more guaranteed than the macro.
The disadvantage of function call: The function call needs some parameters, return the address, etc. into the stack, the overhead of the stack, the efficiency does not have the macro function high.

Four, Putian C + + pen Test

1, the realization of two-way linked list Delete a node p, after the node P insert a node, write these two functions.

Suppose the linear table of bidirectional linked list storage structure typedef struct dulnode{struct Dulnode *prior;//precursor pointer elemtype data//struct dulnode *next;//successor Pointer}d Ulnode,*dulinklist; Insert Node Status listinsert_dul (dulinklist &l,int i,elemtype &e) {if (!) ( P=getelemp_dul (l,i)) return ERROR; if (!) ( S= (dulinklist) malloc (sizeof (Dulnode))) return ERROR; s->data=e; s->prior=p->prior; p->prior->next=s; s->next=p; p->prior=s; return OK; }

2. Write a function to convert t/T to 4 spaces.

#include <string> #include <iostream> using std::string; Using Std::iostream; String Replacetab (String); int main () {string s= "Hello world!"; Std::cout<<replacetab (s); return 0; String Replacetab (string s) {for (int i=0;i<s.length (); i++) {if (s[i]== '/t ') s[i]= ';} return s;}

Another method is:

The function is named convert, and the value of the parameter is: the//*strdest purpose string, the *STRSRC source string, and the length//function of the long source string is: char* convert (char *strdest, const char * Strsrc,int length) {char * CP = strdest int i=0 while (*strsrc && i<length)//jump out of condition {if (*strsrc== '/t ')//Will/ T converts to 4 spaces {for (int j=0;j<4;j++) *cp++= ';} else//otherwise direct copy *cp++=*strsrc; strsrc++; i++; return strdest; }

3. Where is the entrance to the Windows program? Write out the process of the Windows Messaging mechanism.

The portal for Windows programs is the WinMain function.

Message mechanism: The system will maintain one or more message queues, and all messages generated will be placed in or inserted into the queue. Each message is fetched from the queue, and the message is sent to the message loop of the program that owns the window based on the message's receive handle. Each running program has its own message loop, gets its own message in the loop, and invokes the corresponding window procedure based on the handle of the receiving window. In the absence of a message, the message loop gives control over to the system.

4. How to define and implement a member function of a class as a callback function.

The so-called callback function, is in advance of the system to register the function, let the system know the existence of this function, later, when an event occurs, then call the function to respond to the event. When defining a member function of a class, add callback to the function before it is defined as a callback function, and the implementation of the function is no different from the normal member function.

5, C + + inside is not all the action is main () caused. If not, please give an example.

No, for example, interrupt processing caused by interrupts is not caused directly by main (), but by external events.
6, C + + inside how to declare the const void f (void) function is a library function in C program.

Add an extern "C" declaration before this function

7. Which two of the following are equivalent
int b;
A const int* a = &b;
B const* int a = &b;
C const int* Const A = &b;
D int const* const A = &b;
The meanings of various expressions are:
A const int* a = &b; *a is a const, but pointer A is variable
B const* int a = &b; A is a const, but *a variable
C const int* Const A = &b; Both A and *a are const, and the values of constants and pointers cannot be changed
D int const* const A = &b; Both A and *a are const, and the values of constants and pointers cannot be changed
So c,d the two are the same.
Summary tip: If the const is on the left side of the asterisk, the const is used to modify the variable that the pointer points to, that is, the pointer is a constant, and if the const is to the right of the asterisk, the const is the cosmetic pointer itself, that is, the pointer itself is a constant.

8. Inline functions are checked for parameter types at compile time.
Do type checking, because the inline function is when the program compiles, the compiler replaces the invocation expression of the inline function that appears in the program with the function body of the inline function. Five, Datang communication pen test

1, what is interrupted. What the CPU does when the interrupt occurs.

Interrupts are a pattern of CPU response to peripheral requirements, when the peripheral needs the CPU, will send the interrupt request to the interrupt controller, then the CPU wants to protect the scene, namely the running program saves, is generally the state presses the stack, then reads the interrupt number, initiates the corresponding interruption service procedure, after the service completes, loads in the protection scene, That is, the stack of data ejected, continue to run before the program.

2, the CPU after the power, into the operating system main () must do what work.

After the power-on, will trigger the CPU reset signal, resulting in CPU reset, and then the CPU will jump to (under arm under the 0x00000000,x86 0xfffffff0)/execution instructions. Mainly do CPU initialization, to determine the working mode of the CPU, MMU initialization. Create page Table Segment table, initialize the lonely controller and interrupt vector table, initialize input and output, initialize Nandflash, load the OS text area into SDRAM, then jump to SDRAM main ()

3, brief description of ISO OSI physical layer Layer1, link layer Layer2, Network layer Layer3 task.

The main tasks of the physical layer:

(1) The data-terminal device provides a path for transmitting data, which can be a physical medium or multiple physical media connections. A complete data transmission, including activating physical connections, transferring data, terminating physical connections. The so-called activation is that no matter how much physical media is involved, Must be connected to the two data terminals of the communication to form a path.
(2) Transmission of data. The physical layer needs to form an entity suitable for data transmission, for data transfer services. One is to ensure that the data can be passed correctly, the second is to provide sufficient bandwidth (bandwidth refers to the number of bits per second) to reduce congestion on the channel. The data can be transmitted in a way that satisfies the point-to-point One o'clock to multi-point, serial or parallel, Half-duplex or Full-duplex, synchronous or asynchronous transmission needs.
(3) Finish Some management work of the physical layer.

The main task of the link layer: The link layer is to provide data transfer service for the network layer, which depends on the function of the layer.

(1) The establishment, removal and separation of link links.

(2) frame and frame synchronization. The data transmission unit of the link layer is the frame, the protocol is different, the frame length and the interface also have the difference, but the frame must be bound at any rate.
(3) sequential control, which refers to the control of the sequence of frames.

(4) Error detection and recovery

Network layer to establish network connectivity and provide services to the upper level

4. What is the difference between landline and cordless telephone? What you need to pay special attention to is the radio.

Landline cable, can only move within the range of the line, wireless telephone without the limit of lines, there is a signal can be. Wireless telephones need to pay attention to channel interference in particular.

5, software development Five main step is what.

Requirements analysis, System design, System coding, test run, upgrade maintenance

6, when you are developing the software, these 5 step take up the percentage of time respectively.

Requirement analysis in 30%, system design in 15%, system code in 40%, test run in 5%, upgrade maintenance in 10%

7. What is the function of the makefile file?

The makefile file holds the compiler and connector parameter options, as well as the relationships between all source files (the specific inclusion files required by the source code file, the target file modules and libraries included with the executable file). The creation program (make program) reads the makefile file first, The compiler, the assembler, the resource compiler, and the connector are then activated to produce the final output, and typically the executable is output and generated. The creation program uses built-in inference rules to activate the compiler to generate a specific obj file by compiling the specific CPP file.

8, UNIX display folder, the name of the command is what. What commands can make the contents of a file appear on the screen.

(1) L, LC, LS These three commands can display the file name, but the display mode is different
(2) Cat, more, vi can display the contents of the file, but also display different ways

9. What happens to mobile phone users as they roam from one base station to another?

Before exiting the current base station, register at the next base station, and exit from the previous base station when the new channel is registered and opened. Vi. Summary

1, the OSI seven layer model and the TCP/IP four-layer model name and the main functions of each layer.

The OSI seven layer model structure diagram is shown in Figure 1.

Fig. 1 OSI seven-layer model

Physical layer : the lowest or first layer of the O S I model, which includes a physical networking medium, such as a cable-connection connector. The physical layer protocol generates and detects voltages to send and receive signals that carry data. Insert the network interface card on your desktop P C, and you build the foundation of your computer's networking. In other words, you provide a physical layer. Although the physical layer does not provide error correction services, it can set the data transmission rate and monitor the error rate. Network physical problems, such as wire disconnection, will affect the physical layer.

Data Link Layer : The second layer of the O S I model, which controls communication between the network layer and the physical layer. Its main function is how to reliably transmit data on unreliable physical circuits. To ensure transmission, data received from the network layer is segmented into specific frames that can be transmitted by the physical layer. A frame is a structure package that is used to move data, including not only raw data, but also the network address of the sender and receiver, as well as error correction and control information. The address determines where the frame will be sent, and error correction and control information to ensure that the frame is error-free. The data link layer's functionality is independent of the network and its nodes and the physical layer type used, and it does not care whether or not you are running Word, Excel, or using the Internet. There are connection devices, such as switches, that work on the data link layer because they want to decode frames and use frame information to send data to the correct receiver.

Network layer : The third layer of the O S I model, whose main function is to translate the network address into the corresponding physical address and decide how to route the data from the sender to the receiver. The network layer determines the optimal path from Node A in one network to Node B in another network by considering the sending priority, the degree of network congestion, the quality of the service, and the cost of the optional route. Because the network layer processes routing, and routers are connected to the network segments, and intelligent guidance data transfer, belong to the network layer. In a network, "routing" directs the sending of data based on the address scheme, usage patterns, and accessibility.

Transport Layer : The most important layer in the O S I model. The Transfer Protocol simultaneously carries out the flow control or the appropriate rate of transmission based on the degree to which the receiving party can receive the data. In addition, the Transport layer forces longer packets to be segmented according to the maximum size that the network can handle. For example, Ethernet cannot receive packets larger than 1 5 0 0 bytes. The transport layer of the sender node divides the data into smaller data slices and arranges a serial number for each data slice so that the data can be reconstructed in the correct order when it reaches the transport layer of the receiving node. The process is called sort. One service at the transport layer is T C P (Transmission control) in the T C p/i p protocol set, and the other Transport layer service is s p x (sequence Packet Exchange) of I p x/s p x protocol set.

Session Layer : Responsible for establishing and maintaining communication between two nodes in the network. The functions of the session layer include: establishing communication links, keeping the communication links of the session process smooth, synchronizing the conversation between two nodes, deciding whether the communication is interrupted and where to resend it when the communication is interrupted. You can often hear people calling the conversation layer the "traffic policeman" of network communication. When you connect to the Internet by dialing your I p (Internet service Provider), the session layer on the I p server negotiates the connection with the session layer on your P C client. If your phone line accidentally falls off the wall, the session layer on your terminal detects a disconnect and restarts the connection. The session layer sets the communication duration by determining the priority of node communication and the length of communication time.
Presentation Layer : The translation officer between the application and the network, at the presentation layer, the data is formatted according to the solution that the network understands, and the format is different depending on the type of network being used. The presentation layer manages the decryption and encryption of data, such as the processing of system passwords. For example: Check your bank account on the Internet, using a secure connection. Your account data is encrypted before it is sent, and at the other end of the network, the presentation layer decrypts the received data. In addition, the presentation layer protocol decodes and encodes picture and file format information.

Application Layer : is responsible for providing interfaces to the software to enable programs to use network services. The term "Application layer" does not refer to a particular application running on a network, and the services provided by the application layer include file transfer, file management, and information processing of e-mail messages.

The TCP/IP four-tier model is shown in Figure 2:

Figure 2 TCP/IP four-layer model

In practical applications, a compromise approach is often adopted, which combines the advantages of OSI and TCP/IP, and uses a five-layer protocol architecture. namely application layer, Transport layer, network layer, data link layer and physical layer. The functions of each layer are as follows:

(1) Application layer: Determine the nature of the communication between processes (running programs) to meet the needs of the user. It provides the exchange of information required by the application process as well as the functions required by the user agent semantically meaningful information exchange. Commonly used HTTP, FTP, etc. belong to the Application layer protocol.

(2) Transport layer: responsible for communication between the two processes in the host, the transmission unit is the message segment. The transport layer has the functions of multiplexing and division. That is, multiple processes in the transport layer can reuse the following network layer functions. To the network layer of the host, then use the division function, the data to the corresponding process. TCP and connectionless UDP protocols for connection-oriented

(3) Network layer: To provide communication for different hosts on the packet switching network. The transmission units are grouped. Routing is the host function of the network layer. This layer is a connectionless, unreliable protocol.
(4) Data Link layer: The data of frame is transmitted without error on the line between two adjacent nodes. Each frame includes data and necessary control information, and its control information includes: synchronization information, address information, error control and flow control information. The link layer transforms an actual link that is likely to go awry to make the network layer look downward as if it were an error-less link.

(5) Physical layer: transparently transmits the bit stream. The units that are transmitted on the physical layer are bits.
Note: Some of the physical media used to transmit information, such as twisted-pair, coaxial cable, are not included in the layer, transparent meaning: something that actually exists does not seem to exist. The "Transparent transfer of Bit stream" indicates that the bit stream has not changed after the actual circuit is transmitted.

The data transfer process is shown in Figure 3:

Figure 32 Host data transfer process

2, the API functions of some C/A + + are rewritten.

This part of the problem solving methods mainly to understand the core idea of the algorithm can be.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.