C ++ Frequently Asked Interview Questions

1, how to understand object-oriented?

A set of data structures and the method for processing an object thereof, the object of the same class behavior summarized, by hiding the internal details of a class packaging, through inheritance class specialization, generalization of polymorphic Based on the object type of dynamic dispatched.

2, object-oriented and object-based difference?

Object-oriented three characteristics (encapsulation, inheritance, polymorphism) are indispensable. Object-based language is a natural process evolved, belong to structured programming.

3, function polymorphism what's the use?

Polymorphic function has two forms (overloading and cover), the transfer function declaration of the same name may be different parameters for different functions; that is covering the subclass inherits the parent class when the parent can claim with exactly the same function ( name and parameters) to achieve different functions.

4, the difference between the copy constructor and an equal sign?

That alone equals the value assigned to the right of the left, and the left and right sides of the equal sign variable must be declared in advance; the copy constructor can be called when it was declared, if the pointer would have to open up memory space, then the assignment function.

5, how in the designated area a new target?

用placement new

6, int target new time will not be initialized to 0?

If the back can parentheses, such as A * = int int 10

7, the role of virtual destructor?

Remove the base class can be called when the object subclass object destructor

8. What is the role of multi-threaded?

Using multiple threads generally have two different purposes, first, the program is subdivided into several independent functional modules, which prevent a functional module leads blocking entire program suspended animation. Another is to increase operational efficiency, such as multiple cores running at the same time, or when a single core inside thread IO operation, another thread can execute at the same time.

9, multi-threaded What are the benefits?

1: high resource utilization, program design simpler, more responsive program.

10, what is the generic programming?

Generic programming (Generic Programming) motivations when originally proposed is simple and direct: to invent a language mechanism to help achieve a common standard container library. The so-called universal standard container library, is to be able to do, such as using a List class to store objects of all possible types of such things; generic programming allows you to write generic algorithms and completely reusable, and its efficiency for a particular the same data type and design algorithms. Which means having a generic meaning in the multiple data types may be operating characteristics, somewhat similar to the template. STL huge, and can be expanded, it contains many basic computer algorithms and data structures, and complete separation of algorithms and data structures, wherein the algorithm is generic, not together with any particular type or object-based data structures.

11, the role of the main thread?

When a program starts, there is a process by the operating system (OS) to create, at the same time also a thread running immediately, the thread is usually called the main thread of the program (Main Thread), because it is the beginning of the implementation of the program, If you need to create a thread, the child thread thread is the main thread created. Each process has at least one main thread, in Winform, it should be is to create a GUI thread.
The importance reflects the main thread in two ways: 1 is produced thread other sub-thread; it must usually 2 to finalize the implementation of such closed to perform various actions.

12, C ++ how to generate non-repeating random numbers?

This object is an iterator function operation of container that we need to store the data from the array into a container like the following code to achieve this:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

void randperm(int Num)
{
    vector<int> temp;
    for (int i = 0; i < Num; ++i)
    {
        temp.push_back(i + 1);
    }

    random_shuffle(temp.begin(), temp.end());

    for (int i = 0; i < temp.size(); i++)
    {
        cout << temp[i] << " ";
    }
}

cout << endl; 

13, linux core document how to view and call?

First, your Segmentation Fault error must be able to reproduce the (nonsense ...).

Then, according to the reference to the following steps to operate:
(1) Whether you use Makefile to compile, or directly from the command line to compile manually enter the command, you should add the -g option.
(2) In general, by default, when a program crashes, core file is not generated (many Linux distributions forbid core file is generated in default). So, you have to change this default option in the command line: ulimit -c unlimited represents the size does not limit the resulting core file.
(3) run your program, regardless of the method used to make it reproduce Segmentation Fault error.
(4) At this point, you will find in the same directory as your program, it generates a file called core. *** documents, namely core file. For example, "core.15667" such files.
(5) debugging it with GDB. Suppose your executable program named test, then the command line:
gdb the Test core.15667
then may show a bunch of information:

GNU gdb Fedora (6.8-27.el5)

Copyright (C) 2008 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>;

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.  Type "show copying"

and "show warranty" for details.

This GDB was configured as "i386-redhat-linux-gnu"...


warning: Can't read pathname for load map: Input/output error.

…………………(中间还有很多内容,此处省略)……………………………

Loaded symbols for /usr/lib/libgpg-error.so.0

Core was generated by `./test'.

Program terminated with signal 11, Segmentation fault.

[New process 15668]

#0  0x0804c760 in thread _handler () at test.cpp:707

707                             CDev* cur_dev = *it_d;


然后我们输入并执行命令 bt :

(gdb) bt


就会得到类似于下面的信息:


#0  0x0804c760 in thread _handler () at test.cpp:707

#1  0x006b149b in start_thread () from /lib/libpthread.so.0

#2  0x0060842e in clone () from /lib/libc.so.6

于是,我们一眼就看出来了:程序是在第707行使用指针时出的问题。 

14, what big data query optimization is?

1, optimization index; 2 using intermediate table.

15, C ++ class default empty class member functions which generate?

  Empty(); // 缺省构造函数

  Empty( const Empty& ); // 拷贝构造函数

  ~Empty(); // 析构函数

   Empty& operator=( const Empty& ); // 赋值运算符

   Empty* operator&(); // 取址运算符

   const Empty* operator&() const; // 取址运算符 const  

16, a comprehensive summary of the C ++ const

Use const keyword in C ++ is very flexible, and the use const will greatly improve the robustness of the program, I summarized as follows based on the information found in various aspects, expectations for help friends.
Const is the C ++ type commonly used modifiers, usually refers to the value of a variable type or object type using the type described const modifier, type often can not be updated.
const role:
Here Insert Picture Description

17, five kinds of what C ++ memory allocation is?

In C ++, memory is divided into five areas, they are the heap, stack, free store, global / static storage area and the constant storage area.

Stack, who is the storage area when needed allocated by the compiler, automatically clear when not needed variables. Variables which are typically local variables, functions and other parameters.
  Heap is that memory block allocated by malloc and so on, he and the heap is very similar, but it is free to end their lives.
  Free store, are those allocated by the new block of memory, never mind their release compiler, to control by our application, a new general would correspond to a delete. If a programmer is not freed, then at the end of the program, the operating system will automatically recover.
  Global / static storage area, global variables and static variables are allocated to the same memory, the previous C, global variables is divided into initialized and uninitialized in C ++ which do not have this distinction, and they jointly occupy the same a memory area.
  Constant storage area, which is a special storage area, they are stored inside is a constant, not allowed to modify (Of course, you can also change through non-legitimate means, and many ways, the "thinking const" a text, I six methods are given)

18, C ++ cast static_cast and dymic_cast difference in the character?

static_cast also be used wherein the base class and a derived class pointer or a reference to convert between types. However, it does not do run-time checks, as dynamic_cast security. static_cast just rely on the information type conversion statement provided to convert, and dynamic_cast will traverse the entire class inheritance hierarchy type checking, and therefore on the efficiency of static_cast dynamic_cast to be worse than that.

Published 252 original articles · won praise 151 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_39885372/article/details/104257505