Answers to Huawei pen questions

Source: Internet
Author: User
Huawei is engaged in the research, development, production and sales of communication network technologies and products. It is one of the major suppliers of China Telecom and has successfully entered the global telecom market. Every year, Huawei will recruit a large number of professionals from major universities, especially Huazhong University of Science and Technology. Company Website: http://www.huawei.com
The following is said to be the pen test questions of Huawei. In fact, I think it cannot produce so many questions at a written test. It may be a collection of PEN test questions for many years, or it also includes the written test content of other companies. Recently, the Network Management of International Commercial Engineering Group (http://www.ibegroup.com/) told me that this is their problem. It is the problem of Huawei, which I think should be like this, after all, their company's website appears in the question (see question 2). I hope you can write this statement when posting it.
In addition, I found someone in the white clouds and the Yellow Crane posted the answer without declaring the source. I told him seriously that angry was very angry and the consequences were very serious.
Personal answers are for reference only. Haha, but ensure the accuracy of most answers.
1. Write and judge whether the four expressions of ABCD are correct. If so, write the value of A in the expression (3 points)
Int A = 4;
(A) A ++ = (a ++); (B) a ++ = (++ A); (c) (a ++) ++ = A; (d) (++ A) ++ = (a ++ );
A =?
A: C error. The left side is not a valid variable and cannot be assigned a value. You can change it to (++ A) + =;
After the change, the answers are 9, 10, 10, and 11 in sequence.

2. In a 32-bit system, calculate the value of sizeof in the C ++ Program (5 points ).
Char STR [] = "www.ibegroup.com"
Char * P = STR;
Int n = 10;
Calculate
Sizeof (STR) =? (1)
Sizeof (p) =? (2)
Sizeof (n) =? (3)
Void Foo (char STR [1, 100]) {
Calculate
Sizeof (STR) =? (4)
}
Void * P = malloc (100 );
Calculate
Sizeof (p) =? (5)
Answer: (1) 17 (2) 4 (3) 4 (4) 4 (5) 4

3. answer the following question (4 points)
(1) What is the use of ifndef/define/endif in the header file? Preprocessing
A: prevent header files from being repeatedly referenced.
(2). # What is the difference between include and # include "filename. h?
A: the former is used to include the library header files provided by the development environment, and the latter is used to include the header files compiled by yourself.
(3). Why should I add the extern "C" declaration to call the function compiled by the C compiler in the C ++ program?
A: The names of functions and variables in the symbol library after being compiled by C ++ are different from those in the C language. The variables and functions modified by extern "C" are compiled and connected in C language. C ++ programs cannot directly call C functions because their compiled names are different. C ++ provides a C connection to exchange the specified symbol extern "C" to solve this problem.
(4) What data types are not allowed in switch?
Answer: Solid

4. answer the following question (6 points)
(1 ).

Void getmemory (char ** P, int num ){
* P = (char *) malloc (Num );
}
Void test (void ){
Char * STR = NULL;
Getmemory (& STR, 100 );
Strcpy (STR, "hello ");
Printf (STR );
}
What are the results of running the test function?
A: The output is "hello"
(2 ).

Void test (void ){
Char * STR = (char *) malloc (100 );
Strcpy (STR, "hello ");
Free (STR );
If (STR! = NULL ){
Strcpy (STR, "World ");
Printf (STR );
}
}
What are the results of running the test function?
A: output "world" because free (STR) does not change the memory content indicated by Str.
(3 ).

Char * getmemory (void ){
Char P [] = "Hello World ";
Return P;
}
Void test (void ){
Char * STR = NULL;
STR = getmemory ();
Printf (STR );
}
What are the results of running the test function?
A: The pointer is invalid and the output is uncertain.

5. Compile the strcat function (6 points)
It is known that the prototype of the strcat function is char * strcat (char * strdest, const char * strsrc );
Here, strdest is the destination string and strsrc is the source string.
(1) do not call the string library functions of C ++/C. Compile the strcat function.
A:
VC source code:

Char * _ cdecl strcat (char * DST, const char * SRC)
{
Char * CP = DST;
While (* CP)
CP ++;/* Find end of DST */
While (* CP ++ = * SRC ++);/* Copy SRC to end of DST */
Return (DST);/* return DST */
}
(2) Why should strcat connect the content of strsrc to strdest?
A: It is convenient to assign values to other variables.

6. Is cstring a type security class in MFC?
A: No. You can use the cstring member function Format to convert other data types to cstring.

7. Why is a template class used in C ++.
A: (1) create a Data Structure with dynamic growth and reduction
(2) It is type-independent and therefore highly reusable.
(3) It checks the data type during compilation instead of runtime, ensuring the type security.
(4) It is platform-independent and portable.
(5) can be used for basic data types

8. What does csinglelock do.
A: Synchronize multiple threads to simultaneously access a data class.

9. What is newtextmetric.
Answer: The physical font structure is used to set the font height, width, and size.

10. When the program should use the thread, and when the single thread is highly efficient.
Answer: 1. Time-consuming operations use threads to improve application response
2. threads are used for parallel operations, such as the concurrent threads on the server side in the C/S architecture to respond to user requests.
3. In multiple CPU Systems, threads are used to improve CPU utilization
4. Improve the program structure. A long and complex process can be considered to be divided into multiple threads and become several independent or semi-independent running parts. Such a program will facilitate understanding and modification.
In other cases, a single thread is used.

11. Is windows a kernel-level thread.
A: see the next question.

12. Does Linux have kernel-level threads.
A: A thread is usually defined as a different execution route of code in a process. There are two types of threads: user-level threads and kernel-level threads ". A user thread is a thread implemented in a user program without kernel support. It does not depend on the core of the operating system, the application process uses the thread library to provide functions for creating, synchronizing, scheduling, and managing threads to control user threads. This kind of thread can be implemented even in operating systems like DOS, but the thread scheduling needs to be completed by the user program, which is similar to Windows 3.x collaborative multitasking. In addition, the kernel needs to participate in thread scheduling. It depends on the operating system core and is created and abolished by the internal requirements of the kernel. These two models have their own advantages and disadvantages. The user thread does not require additional kernel expenses, and the Implementation Mode of the user State thread can be customized or modified to meet the requirements of special applications, however, when a thread is in the waiting state due to I/O, the whole process will be switched to the waiting state by the scheduler, and other threads will not be able to run; there are no restrictions on Kernel threads, which are conducive to the advantage of multi-processor concurrency, but occupy more system expenses.
Windows NT and OS/2 support kernel threads. Linux supports kernel-level Multithreading

13. In C ++, what data is distributed in the stack or heap. Is the new data allocated in the near or remote heap?
A: Stack: stores local variables, function call parameters, function return values, and function return addresses. Managed by System
Heap: dynamically applied when the program is running, and the memory applied for by new and malloc is on the heap.
It is not clear whether the near heap is a remote heap.

14. How does a thread prevent large peaks.
A: It indicates how to prevent a large number of threads from being generated at the same time by using the thread pool. The thread pool can improve the scheduling efficiency and limit resource usage at the same time, when the maximum number of threads in the thread pool is reached, other threads will wait in queue.

15 What are the differences between function templates and class templates?
A: The instantiation of a function template is automatically completed by the compiler when processing the function call. The instantiation of a class template must be explicitly specified by the programmer in the program.

16 what will happen if the logs in the database are full?
A: You can only perform read operations such as query, modification, backup, and other write operations, because logs must be recorded for any write operations. That is to say, it is basically in an unusable state.

17 does SQL server support row-level locks?
A: Yes. The blocking mechanism is mainly used to control concurrent operations and block interference to ensure data consistency and accuracy, row-level blocking ensures that the updated row is not modified by other users during this period. Therefore, row-level locks can ensure data consistency and improve data operation bursts.

18 if the database is full, what can I do?
A: see section 16.

19. Memory alignment and sizof () Output
Answer: The reason for automatic compiler alignment: To improve program performance, data structures (especially stacks) should be alignment on natural boundaries as much as possible. The reason is that the processor needs to perform two memory accesses to access non-alignment memory; however, alignment memory access only needs one access.

20 int I = 10, j = 10, K = 3; K * = I + J; what is the final value of K?
Answer: 60. The priority of this question is actually written as K * = (I + J). The assignment operator has the lowest priority.

21. how to operate a table in the database and another table?
A: Put the operations that operate on multiple tables into transactions for processing.

22. What is the process of establishing a connection with TCP/IP? (3-way shake)
A: In TCP/IP, TCP provides reliable connection services and uses three handshakes to establish a connection.
First handshake: when a connection is established, the client sends the SYN Packet (SYN = J) to the server and enters the syn_send status. Wait for the server to confirm;
The second handshake: when the server receives the SYN packet, it must confirm the customer's Syn (ACK = J + 1) and send a SYN Packet (SYN = K), that is, the SYN + ACK packet, the server enters the syn_recv status;
The third handshake: the client receives the server's SYN + ACK package and sends the ACK (ACK = k + 1) Confirmation package to the server. After the package is sent, the client and server enter the established status, complete three handshakes.

23. What protocol is ICMP and what layer is it?
Answer: The Internet Control Packet protocol is at the network layer (IP layer)

24. How does a trigger work?
A: A trigger is executed when an event is triggered. When you perform operations such as update, insert, and delete on a table, the database will automatically execute the SQL statements defined by the trigger to ensure that the data processing must comply with the rules defined by these SQL statements.

25. How does Winsock establish a connection?
A: On the server side: socker () establishes a socket, binds (BIND) and listens (Listen), and waits for the client to connect with accept.
Client: socker () establishes a socket and connects to the (CONNECT) server. After the connection, use send () and Recv () to write and read data on the socket until the data exchange is complete. closesocket () close the socket.
Server: accept () finds a client connection, creates a new socket, and waits for the connection again. The new socket uses send () and Recv () to write and read data until the data exchange is complete, closesocket () closes the socket.

26. How can I dynamically connect to a database?
A: There are two methods to call a function in a DLL:
1. Load-Time Dynamic Linking. The module clearly calls an export function to make it look like a local function. This requires linking the DLL import and export of those functions, and providing the information required for loading the DLL and positioning the DLL functions to the system.
2. Run-Time Dynamic Linking. You can use the loadlibrary or LoadLibraryEx function to load the DLL during running. After the DLL is loaded, the module can call getprocaddress to obtain the exit address of the DLL function, and then call the DLL function through the returned function pointer. In this way, you can avoid importing and receiving files.

27. What are the benefits of IP multicast? A: Many new applications on the Internet, especially high-bandwidth multimedia applications, bring about sharp bandwidth consumption and network congestion problems. Multicast is a network technology that allows one or more senders (Multicast sources) to send a single packet to multiple receivers (one-time and simultaneous. Multicast can greatly save network bandwidth, because no matter how many destination addresses there are, only a single packet is transmitted on any link of the network. Therefore, the core of multicast technology is to ensure service quality on the premise of Saving network resources.
 

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.