Huawei C/C ++ pen questions (with answers, Huawei Interview Questions series)

Source: Internet
Author: User

1. What is the purpose of static? (Please specify at least two types)
1) In the function body, a variable declared as static remains unchanged when the function is called.
2) in a module (but in the function body), a variable declared as static can be accessed by the function used in the module, but not by other functions outside the module. It is a local global variable.
3) in a module, a function declared as static can only be called by other functions in the module. That is, this function is restricted to use within the local scope of the module that declares it.

2. What is the difference between reference and pointer?
1) The reference must be initialized and the pointer is not required.
2) The reference cannot be changed after initialization. the pointer can change the object.
3) There is no reference pointing to a null value, but there is a pointer pointing to a null value.

3. Describe the basic features of the Real-Time System
Complete specific tasks within a specific period of time, real-time and reliability.

4. Are global variables and local variables different in memory? If so, what is the difference?
Global variables are stored in the static database, and local variables are stored in the stack.

5. What is a balanced binary tree?
Both left and right Subtrees are balanced binary trees, and the absolute value of the depth difference between left and right Subtrees is not greater than 1.

6. What causes stack overflow?
No garbage collection resources are collected.

7. What functions cannot be declared as virtual functions?
The constructor function cannot be declared as a virtual function.

8. Bubble SortingAlgorithmWhat is the time complexity?
The time complexity is O (n ^ 2 ).

9. Write the if statement for comparing float X with "zero value.
If (x> 0.000001 & x <-0.000001)

10. What network protocol does the Internet use? What is the main hierarchy of the protocol?
TCP/IP protocol
The main layers are application layer, transmission layer, network layer, data link layer, and physical layer.

11. What protocol does the physical and IP address translation use for the Internet?
ARP (Address Resolution Protocol) (Address Resolution proposal)

12. What are the two parts of IP address encoding?
An IP address consists of a network number and a host number. However, it is only after bitwise AND top-up with the "subnet mask" that the network bit and host bit are distinguished.

13. The user inputs the M and N values. The number of sequential loops starts from 1 to n. This value is output on every count to m until all are output. Write cProgram.
Cyclic linked list, with the remainder operation

14. The parameter types that cannot be switched () are:
The Switch Parameter cannot be of the actual type.

 

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 [] = "http://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 I nclude and # I nclude "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 name of the function and variable in the symbol library after being compiled by C ++ is different from that in the C language. It is modified by extern "C ".
The number and function are compiled and connected in C language. C ++ programs cannot be directly called because the compiled name is different.
Use the C function. 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);
}< br> void test (void) {
char * STR = NULL;
getmemory (& STR, 100);
strcpy (STR, "hello ");
printf (STR);
}< br> what is the result of running the test function?
answer: output "hello"
(2 ). void test (void) {
char * STR = (char *) malloc (100);
strcpy (STR, "hello ");
free (STR);
If (STR! = NULL) {
strcpy (STR, "world");
printf (STR );
}< BR >}< br> what is the result of running the test function?
answer: output "world"
(3 ). char * getmemory (void) {
char P [] = "Hello World";
return P;
}< br> void test (void) {
char * STR = NULL;
STR = getmemory ();
printf (STR );
}< br> what is the result of running the test function?
answer: 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 divided into multiple threads to become several independent or semi-independent processes.
Such a program is easy to understand and modify.
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 process.Code. In terms of implementation methods, there are two threads
Type: "user-level thread" and "kernel-level thread ". User threads refer to user programs without kernel support
Is independent of the core of the operating system. The application process uses the thread library to provide creation, synchronization, and scheduling.
And manage thread functions to control user threads. This kind of thread can be implemented even in an operating system like DOS.
But thread scheduling needs to be completed by the user program, which is similar to Windows 3.x collaborative multitasking. Another
And the kernel completes thread scheduling. It depends on the core of the operating system.
The two models have their own advantages and disadvantages. The user thread does not need additional kernel expenses
And the implementation method of user-state threads can be customized or modified to meet the requirements of special applications.
When the process is in the waiting state due to I/O, the whole process will be switched to the waiting state by the scheduling program.
But there are no restrictions on Kernel threads, which is conducive to taking advantage of multi-processor concurrency.
More system expenses are used.
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.

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.
High scheduling efficiency and resource usage restrictions. When the maximum number of threads in the thread pool is reached, other threads will queue
Wait.

15 What are the differences between function templates and class templates?
A: The function template is automatically instantiated by the compiler when processing the function call.
It 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.
Log recording. 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 security.
Consistency and accuracy. the row-level blocking ensures that the user does not update the row obtained by the user to the row during this period.
Modified by other users. 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 as much as possible.
Alignment on the natural boundary. The reason is that the processor needs to perform two memory accesses to access the Non-Alignment memory.
However, alignment memory access only requires 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
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
SYN Packet (SYN = K), that is, SYN + ACK packet. At this time, the server enters the syn_recv status;
Third handshake: the client receives the server's SYN + ACK packet and sends the ACK (ACK = k + 1) Confirmation packet to the server)
After the package is sent, the client and server enter the established status and 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 a table is updated or inserted
And delete, the database automatically executes the SQL statement defined by the trigger to ensure
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 () creates a socket, binds (BIND), listens (Listen), and uses accept ()
Wait for the client to connect.
Client: socker () establishes a socket, connects to the (CONNECT) server, and uses send () and Recv (
), Write and read data on the socket until the data exchange is complete, closesocket () closes 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, closesock
Et () 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.
So that they are like local functions. This requires linking the DLL import and export of those functions to the database.
The system provides the information required to load the DLL and locate the DLL function.
2. Run-Time Dynamic Linking. You can use loadlibrary or loa
The dlibraryex function loads the DLL. After the DLL is loaded, the module can call getprocaddress to obtain
Export address, and then you can call the DLL function through the returned function pointer. This avoids 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 a sharp increase in bandwidth.
Network congestion. Multicast allows one or more senders (Multicast sources) to send a single packet.
To multiple receivers (one-time, simultaneous) network technology. Multicast can greatly save network bandwidth because
The number of target addresses that can transmit only a single packet on any link of the network. So Multicast
The core of 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.