Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the 16 commonly used cCompact + interview questions?

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

The main content of this article is to explain "what is the interview question with 16 cripples commonly used". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the 16 commonly used cswab casks + interview questions"?

1. What is the function of static in C

(1) hiding. When we compile multiple files at the same time, all global variables and functions without static prefix have global visibility, so we use static to define functions and variables with the same name in different files without having to worry about naming conflicts.

(2) the second function of static is to keep the contents of variables persistent. Variables stored in the static data area are initialized as soon as the program starts, and it is the only initialization. There are two types of variables stored in static storage: global variables and static variables.

(3) the third function of static is to initialize 0. 0 by default. In fact, global variables also have this property, because global variables are also stored in static data areas. In static data areas, the default value of all bytes in memory is 0 × 00, which in some cases can reduce the workload of programmers.

2. What is the use of const in Category +?

Don't say it is constant as soon as you hear const, which gives the examiner the feeling that he is talking to a layman. It should be said that the content of const modification can not be changed, the definition of constants is only a way to use it, there are const data members, const parameters, const return values, const member functions, etc., things modified by const are forcibly protected, can prevent accidental changes, can improve the robustness of the program.

3. How do C and C++ define constants respectively? What's the difference?

In C, the macro # define definition is used, while C++ uses a better const definition. Difference:

1) const is a constant with data types, while macro constants are not. The compiler can perform static type safety checks on the former, only character substitution, no type safety checks on the latter, and unexpected errors (marginal effect) may occur during character substitution.

2) some compilers can debug const constants, but not macros.

4. Why use macros when there is a better const in C++?

Const cannot replace macros as an outpost to prevent duplicate inclusions of files.

5. What is the difference between references and pointers in C++?

Reference is an alias of an object, and operation reference is to manipulate this object. It must be initialized effectively at the same time as it is created (reference to a valid object, not NULL). After initialization, it can no longer be changed. Reference has the efficiency of pointers, as well as the convenience and intuition of variable use. At the language level, references are the same as objects. At the binary level, references are usually implemented through pointers, but the compiler helps us complete the conversion. The reason why references are used is to do the right thing with the right tools, reflecting the principle of least privilege.

6. Tell me about the memory allocation between C and C++?

1) allocate from static storage area. Memory is allocated when the program is compiled, and it exists throughout the run of the program, such as global variables, static variables.

2) create it on the stack. When the function is executed, the storage units of local variables within the function can be created on the stack, and these storage units are automatically released at the end of the function execution. The stack memory allocation operation is built into the instruction set of the processor, which is very efficient, but the allocated memory capacity is limited.

3) allocate from the heap (dynamic memory allocation) the program uses malloc or new to request any amount of memory at run time, and the programmer is responsible for releasing memory with free or delete. The lifetime of dynamic memory is determined by itself, and its use is very flexible.

7. What is the difference between new/delete and malloc () / free ()?

Malloc () and free () are standard library functions of the C language. New/delete is the operator of C++. They can both be used to request and free memory. Malloc () and free () are not under the control of the compiler and cannot impose the task of constructors and destructors on them.

8. What's the difference between # include and # include "a.h"?

A: for # include, the compiler searches a.h from the standard library path. For # include "a.h", the compiler starts searching for a.h from the user's work path.

9. Why add extern "C" when calling a function compiled by C compiler in C++ program?

C++ language supports function overloading, while C language does not support function overloading. The name of the function compiled by C++ in the library is different from that of the C language. Suppose the prototype of a function is: void foo (int x, int y); the function is compiled by the C compiler and the name in the library is _ foo, while the C++ compiler produces names like _ foo_int_int. C++ provides C connection exchange designated symbol extern "C" to solve the name matching problem.

10. What is polymorphism in C++? How is it realized?

Polymorphism is the third basic feature of object-oriented programming language after data abstraction and inheritance. It is the polymorphism that occurs at run time through derived classes and virtual functions. Base class and derived class use the same function name to perform different operations and implement another kind of interface that is isolated from each other, that is, to separate "w h a t" from "h o w". Polymorphism improves the organization and readability of the code, and virtual functions are isolated differently according to different types.

11. What are dynamic characteristics?

In the vast majority of cases, the functionality of the program is determined at compile time, which we call static features. On the contrary, if the function of the program can only be determined at run time, it is called dynamic characteristic. In C++, virtual functions, abstract base classes, dynamic binding and polymorphism make up excellent dynamic features.

twelve。 What is encapsulation? How is it realized in C++?

Encapsulation comes from the design concept of information hiding, which is through the combination of features and behavior to create new data types to isolate the interface from the specific implementation. C++ is implemented through classes, in order to avoid the behavior of one module from interfering with other modules in the same system, we should let the module only expose the interfaces that must be known to the outside world.

13. What is RTTI?

RTTI means that runtime type identification (Run-time type identification) determines the exact type of an object when there is only one pointer or reference to the base class.

14. What is a copy constructor?

It is the constructor of a single parameter, whose arguments are (often) references to objects of the same class; in the class definition, C++ provides a default copy constructor if its own copy constructor is not provided. the default copy constructor completes the copy from member to member

15. What is a deep and shallow copy?

Shallow copy is to create an object to initialize it with a ready-made object, it only copies the members (simple assignment) and does not copy the resources assigned to the members (such as dynamic memory allocated to its pointer variable members); deep copy is when an object is created, if resources are allocated, you need to define your own copy constructor to copy not only the members but also the resources assigned to it.

16. The advantages of object-oriented programming?

Short development time, high efficiency and high reliability. The coding of object-oriented programming has high reusability, and a large number of mature class libraries (such as STL) can be used in application programs. Although the development time is short, the software is easy to maintain and upgrade.

At this point, I believe you have a deeper understanding of "what are the 16 commonly used cripples + interview questions". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report