Here are 50+ commonly asked C++ interview questions and answers which will definitely help you out to ***** one of the toughest interviews.
这里有50多个C ++面试常见问题和答案,这些绝对可以帮助您攻克最艰难的面试之一。
1. What is Object Oriented Programming Approach? Object Oriented Programming is an approach that provides a way of modularizing programs by creating partitioned memory area for data as well as functions that can be used as templates for creating copies of such modules on demand. OOP allows decomposition of a problem into a number of entities called Objects and then builds data and functions around these objects.
1.什么是面向对象的编程方法? 面向对象编程是一种方法,它通过创建数据的分区存储区以及可用作按需创建此类模块副本的模板的功能,来提供一种使程序模块化的方法。 OOP允许将问题分解成许多个称为Objects的实体,然后围绕这些对象构建数据和功能。
2. What is a Class? An entire set of data and code of an object can be made user-defined data type using a class. Objects are variables of Class type. Once a Class has been defined, we can create numerous Objects of its type. A Class is a collection of Objects of similar type.
2.什么是班级? 可以使用类将对象的整个数据和代码集设置为用户定义的数据类型。 对象是Class类型的变量。 一旦定义了一个类,我们就可以创建许多类型的对象。 类是相似类型的对象的集合。
3. What is Hierarchical Inheritance? Hierarchical Inheritance occurs when traits of one Class is inherited by more than one classes.
3.什么是层次继承? 当一个类的特征被一个以上的类继承时,就会发生层次继承。
4. What are Iterators in C++ STL? Iterators behave similar to Pointers and are used to access container elements. They are used to traverse from one element to another. This process is known as ‘iterating through the container’.
4. C ++ STL中的迭代器是什么? 迭代器的行为类似于指针,并用于访问容器元素。 它们用于从一个元素遍历到另一个元素。 此过程称为“遍历容器”。
5. What is Polymorphism? It is the ability to showcase or exhibit different behaviors under different instances. The process of making and Operator or a Function behave differently in different instances is known as Operator Overloading.
5.什么是多态? 它是在不同情况下展示或展示不同行为的能力。 制作和运算符或功能在不同情况下的行为不同的过程称为运算符重载。
6. What is iostream? iostream is a header file in C++. It includes function prototypes for Standard Input Output Functions which include definitions for cout and cin too. The header file is declared as #include<iostream>
6.什么是iostream? iostream是C ++中的头文件。 它包括标准输入输出功能的功能原型,其中也包括cout和cin的定义。 头文件被声明为#include <iostream>
7. What is Dynamic Binding? Binding is the linking of a procedure call to the code to be executed in response to the call. Dynamic Binding is also know as Late Binding which means that the code associated with a given procedure call is unknown until the time of call at run-time.
7.什么是动态绑定? 绑定是将过程调用链接到要响应该调用执行的代码。 动态绑定也称为后期绑定,这意味着与给定过程调用关联的代码在运行时调用之前是未知的。
8. What are the applications of Object Oriented Programming? The areas of applications for OOP includes: 1. Artificial Intelligence Systems 2. Simulation and Modelling 3. Real-Time Systems 4. Neural networks and Parallel Programming 5. Object Oriented Databases
8.面向对象程序设计有哪些应用? OOP的应用领域包括: 1.人工智能系统 2.仿真和建模 3.实时系统 4.神经网络和并行编程 5.面向对象的数据库
9. What is a Destructor? A Destructor is used to destroy the objects that have been created by Constructor. It is basically used to clean up storage that is no longer accessible. A Destructor is a member function. Its name is the same as the class name but is preceded by a Tilde.
9.什么是析构函数? 析构函数用于销毁由构造函数创建的对象。 它基本上用于清理不再可访问的存储。 析构函数是成员函数。 它的名称与类名称相同,但前面带有波浪号。
10. What is a Namespace? It is mandatory that all the C++ programs must include Namespaces. Namespaces in C++ defines a scope for the identifiers that are used in the program.
10.什么是命名空间? 所有C ++程序都必须包含命名空间,这是强制性的。 C ++中的命名空间定义了程序中使用的标识符的范围。
11. What is Enumerated Data Type? An Enumerated Data Type is another User-Defined Type which provides a way for attaching numbers, thereby increasing comprehensibility of the program code. The enum keyword automatically enumerates a list of words by assigning them values 0,1,2,3, and so on.
11.什么是枚举数据类型? 枚举数据类型是另一种用户定义类型,它提供了一种附加数字的方式,从而提高了程序代码的可理解性。 enum关键字通过为单词分配值0、1、2、3等自动枚举单词列表。
12. What are Lists in C++ STL? A List is another very important Container in C++. It supports bidirectional, linear list and provides and efficient implementation for deletion and insertion operatons. A List can only be sequentially accessed.
12. C ++ STL中的列表是什么? 列表是C ++中另一个非常重要的容器。 它支持双向线性列表,并为删除和插入操作提供有效的实现。 列表只能顺序访问。
13. Enlist Operators in C++. new Memory allocation operator .* Pointer to Member Operator endl Line feed operator :: Scope Resolution Operator ::* Pointer to Member Declarator delete Memory Release Operator ->* Pointer to Member Operator setw Field width operator
13.招募C ++的操作员。 新的内存分配运算符 。*指向成员运算符的指针 endl换行符 ::范围解析运算符 :: *指向成员声明 符的 指针 删除内存释放运算符 -> *指向成员运算符的指针 setw字段宽度运算符
14. Explain catch block in C++ Exception Handling. A catch block is defined by keyword catch that catches Exceptions thrown in by throw block and then handles it accordingly. The catch block that intercepts an exception immediately follow the try block that throws the exception. There can be multiple catch statements in a single program.
14.说明C ++异常处理中的catch块。 catch块由关键字catch定义,该catch捕获throw块引发的异常,然后进行相应的处理。 拦截异常的catch块紧跟在引发异常的try块之后。 一个程序中可以有多个catch语句。
15. What is Function Prototyping? A Function Prototype depicts the function interface to the compiler by providing the details regarding Number and Type of arguments and the type of return values. With function or method prototyping, a template is always used when declaring and defining a function.
15.什么是功能原型? 函数原型通过提供有关参数的数量和类型以及返回值的类型的细节来描述编译器的函数接口。 通过函数或方法原型,在声明和定义函数时始终使用模板。
16. What is the ifstream() method? ifstream() method provides input operations. It contains open() method with default input mode. It also inherits functions such as get(), getline(), read(), seekg() and tellg() functions from istream.
16.什么是ifstream()方法? ifstream()方法提供输入操作。 它包含带有默认输入模式的open()方法。 它还从istream继承了诸如get(),getline(),read(),seekg()和tellg()函数之类的函数。
17. What is Multilevel Inheritance? The mechanism of deriving a Class from a previously Derived Class is known as Multiple Inheritance.
17.什么是多级继承? 从先前派生的类派生类的机制称为多重继承。
18. What is an Object? Objects are basic Run-Time entities in an Object oriented system. They may represent a place, a bank account or a person. Objects are essentially the variables that are of Class types.
18.什么是对象? 对象是面向对象系统中的基本运行时实体。 他们可能代表一个地点,一个银行帐户或一个人。 对象本质上是属于类类型的变量。
19. What is an Inline Function? To eliminate the cost of calls and few other overheads to small functions, C++ provides a new feature called Inline Function. An inline function is a function that is expanded in line when it is invoked. This helps to save memory space. This is some what similar to Macro Expansion.
19.什么是内联函数? 为了消除调用成本和对小函数的其他开销,C ++提供了一项称为“内联函数”的新功能。 内联函数是在调用时在行中扩展的函数。 这有助于节省内存空间。 这与宏扩展类似。
20. What are Visibility Labels in C++? The keywords Public, Protected and Private are known as Visibility Labels in C++. By default, the members of any Class are private. A Class which has a Visibility label private is completely hidden from the external environment and does not serve any purpose. A Class with Public Label is visible to the other functions and classes.
20. C ++中的可见性标签是什么? 关键字Public,Protected和Private在C ++中称为“可见性标签”。 默认情况下,任何类的成员都是私有的。 具有可见性标签为private的类对外部环境完全隐藏,没有任何用处。 具有公共标签的类对其他功能和类可见。
21. What are Derived Containers in C++ STL? The Characteristics of a Static Data Member Variable are: 1. It is initialized to Zero when the first object of its Class are created. 2. It is visible only within that class, but its lifetime is the entire program. 3. Only one copy of that member is created for the entire class and is shared by all the objects of that class irrespective of the number of objects are created.
21.什么是C ++ STL中的派生容器? 静态数据成员变量的特征是: 1.在创建其类的第一个对象时,将其初始化为零。 2.仅在该类中可见,但是其生命周期是整个程序。 3.仅为整个类创建该成员的一个副本,并且该副本的所有对象共享该副本,而与创建对象的数量无关。
22. Enlist the characteristics of Friend Functions. 1. It is not in the scope of the class to which it has been declared as a Friend. 2. Since it’s not in the scope of the class, it cannot be called using Object of that Class. 3. It can be invoked like a normal function without the help of any object. 4. Usually , it has the Objects as Arguments. 5. It can be declared either in public or in the private part of a Class without affecting its meaning.
22.征集好友功能的特征。 1.它不在声明为Friend的类的范围内。 2.由于它不在类的范围内,因此无法使用该类的Object进行调用。 3.可以像普通函数一样调用它,而无需任何对象的帮助。 4.通常,它具有对象作为参数。 5.可以在类的公共部分或私有部分中声明它,而不会影响其含义。
23. What is a Constructor? A Constructor is a special member function whose primary task is to initialize objects of its class. The constructor is invoked whenever an object of its class with which it is associated to is created. It is named as constructor because it constructs the values of class data members. It is special because its name is the same as its class name.
23.什么是构造函数? 构造函数是一个特殊的成员函数,其主要任务是初始化其类的对象。 每当创建与其关联的类的对象时,就会调用构造函数。 之所以命名为构造器,是因为它构造了类数据成员的值。 这很特别,因为它的名称与类名相同。
24. What is Hybrid Inheritance? A Hybrid Class is the one that is derived from numerous classes; it can be derived from a parent as well as a child class. There is no sequence as such. It all depends on the needs of such a class.
24.什么是混合继承? 混合类是从多个类派生的。 它可以派生自父类和子类。 没有这样的顺序。 这完全取决于此类的需求。
25. What are cout and cin? cout is the object of ostream class. The cout stream is by default linked to console output device.It is basically used to output the characters on the console screen. It similar to printf in C. cin is the object of istream class. The cin stream is by default linked to console input device. It is basically used to extract the characters form the User. It similar to scanf in C.
25.什么是cout和cin? cout是ostream类的对象。 cout流默认情况下链接到控制台输出设备,它基本上用于在控制台屏幕上输出字符。 它类似于C. cin中的 printf 是istream类的对象。 cin流默认情况下链接到控制台输入设备。 它基本上用于从用户中提取字符。 它类似于C中的scanf。
26. What is a Virtual Function? When a method is declared as Virtual method, the C++ compiler determines which function should be used as runtime based on the type of object pointed to by the base pointer, rather than the type of pointer. When we use the same method name in derived as well as base class, the method in base class is declared a virtual using the keyword virtual preceding its normal declaration.
26.什么是虚拟功能? 当将一个方法声明为Virtual方法时,C ++编译器将根据基本指针指向的对象类型(而不是指针的类型)确定将哪个函数用作运行时。 当我们在派生类和基类中使用相同的方法名称时,基类中的方法在其常规声明之前使用关键字virtual声明为虚拟。
27. What is Data Abstraction? Data Abstraction is basically representing important features without taking care of the background details and information. Since the Classes use concept of Data Abstraction, they are known as Abstract Data Types. STL povides three derived containers named as Queue, Stack and Priority_Queue. These are also known as Container Adapters. These can be developed from different Sequence containers. All of them offer two main functions viz., push() and pop().
27.什么是数据抽象? 数据抽象基本上代表了重要的功能,而无需关心背景细节和信息。 由于类使用数据抽象的概念,因此它们被称为抽象数据类型。 STL将三个派生的容器命名为Queue,Stack和Priority_Queue。 这些也称为容器适配器。 这些可以从不同的Sequence容器开发。 它们都提供两个主要功能,即push()和pop()。
28. What are static Data Members in C++? The Characteristics of a Static Data Member Variable are: 1. It is initialized to Zero when the very first object of its Class are created. 2. It is visible only within that class, but its lifetime is the entire program. 3. Only single copy of that member is created for the whole class and is shared by all the objects of that class irrespective of the number of objects created.
28.什么是C ++中的静态数据成员? 静态数据成员变量的特征是: 1.在创建其类的第一个对象时,将其初始化为零。 2.仅在该类中可见,但是其生命周期是整个程序。 3.仅为整个类创建该成员的单个副本,并且该类的所有对象共享该成员的副本,而与创建的对象数量无关。
29. Enlist the characteristics of Friend Functions. 1. Usually, it has the Objects as Arguments. 2. As it’s not in the scope of the class, it cannot be called using Object of that Class. 3. It is not in the scope of the class to which it has been declared as a Friend. 4. It can be declared either in public or in the private part of a Class without affecting its meaning. 5. It can be invoked like a normal function without the help of any object.
29.登记好友功能的特征。 1.通常,它具有对象作为参数。 2.由于它不在类的范围内,因此无法使用该类的Object进行调用。 3.它不在声明为Friend的类的范围内。 4.可以在某个类的公共或私有部分中声明它,而不会影响其含义。 5.可以像普通函数一样调用它,而无需任何对象的帮助。
30. What is a Constructor? A Constructor is a special member function or a method whose task is to initialize objects of its class. It’s name is the same as its class name. The constructor is invoked whenever an object of its associated class is created. It is named as constructor because it constructs the values of data members of the class.
30.什么是构造函数? 构造函数是一个特殊的成员函数或方法,其任务是初始化其类的对象。 它的名称与它的类名相同。 每当创建其关联类的对象时,就会调用构造函数。 之所以命名为构造器,是因为它构造了类的数据成员的值。
31. What is Hybrid Inheritance? A Hybrid Class is the one that is derived from numerous classes; it can be derived from a parent as well as a child class. There is no sequence as such. It all depends on the needs of such a class.
31.什么是混合继承? 混合类是从多个类派生的。 它可以派生自父类和子类。 没有这样的顺序。 这完全取决于此类的需求。
32. What is STL? STL stands for Standard Template Library. It is a software library for C++ programming language that influenced many parts of C++ Standard Library. Using STL can save considerable time and effort leading to high quality programs. STL components are defined in namespace std.
32.什么是STL? STL代表标准模板库。 它是C ++编程语言的软件库,影响了C ++标准库的许多部分。 使用STL可以节省大量时间和精力,从而可以生成高质量的程序。 STL组件在名称空间std中定义。
33. What is this Pointer? C++ makes use of a unique keyword called this to represent an object that invokes a member function. It is a pointer that points to the object for which this function was called. For example, the function B.min() will set the pointer this to the address of the object B.
33.这是什么指针? C ++使用称为this的唯一关键字来表示一个调用成员函数的对象。 它是一个指向该函数被调用的对象的指针。 例如,函数B.min()会将指针设置为对象B的地址。
34. What is eof() method used for? eof() method returns a Non Zero Value if end-of-file is encountered while reading, else it returns a Zero.
34. eof()方法用于什么? 如果在读取时遇到文件结尾,则eof()方法返回非零值,否则返回零。
35. What is ofstream() method? This method provides output operations. It contains open() method with default output mode. It also inherits functions such as put(), seekp(), tellp(), and write() functions from istream.
35.什么是ofstream()方法? 此方法提供输出操作。 它包含具有默认输出模式的open()方法。 它还从istream继承了put(),seekp(),tellp()和write()函数等功能。
36. What is a Vector in STL? A Vector is one of the most widely used containers in C++. It stores the elements in contiguous memory locations and provides direct access to every element using the subscript operator. A Vector can modify its size dynamically and hence allocates the memory as needed at run time.
36.什么是STL中的向量? Vector是C ++中使用最广泛的容器之一。 它将元素存储在连续的内存位置中,并使用下标运算符直接访问每个元素。 Vector可以动态修改其大小,因此可以在运行时根据需要分配内存。
37. How do we access Virtual Functions? We must access virtual functions through the use of pointer declared as a pointer to the base class. Run Time Polymorphism is achieved only when a virtual method is accessed through a pointer to the base address.
37.我们如何访问虚拟功能? 我们必须通过使用声明为指向基类的指针的指针来访问虚拟函数。 仅当通过指向基地址的指针访问虚拟方法时,才能实现运行时多态。
38. What is Encapsulation? Wrapping up data and functions into a single unit or a block called as a Class is know as Encapsulation. This insulation of data from direct access by the program is called Data Hiding. The data is therefore inaccessible to the external world; only the functions wrapped inside class can access it.
38.什么是封装? 将数据和功能包装到单个单元或称为类的块中被称为封装。 防止程序直接访问的这种数据隔离称为“数据隐藏”。 因此,外部世界无法访问这些数据。 只有包装在类中的函数才能访问它。
39. What is a Stream Class? The C++ Input/Output consists of a hierarchy of classes that are used to define various streams to deal with the console files as well as disk files. These classes are called a Stream Classes and are declared in the header file iostream.
39.什么是流类? C ++输入/输出包含一个类的层次结构,这些类用于定义各种流以处理控制台文件和磁盘文件。 这些类称为流类,并在头文件iostream中声明。
40. What is Multiple Inheritance? A Derived Class with multiple Base Classes is called Multiple Inheritance.
40.什么是多重继承? 具有多个基类的派生类称为多重继承。
41. What are Maps? A map is a sequence of key, value pairs where a single value is associated with each unique key. Retrieval of values is based on the key and is quick. We need to specify the key to obtain the associated values .
41.什么是地图? 映射是键,值对的序列,其中一个值与每个唯一键相关联。 取值是基于键的,并且很快。 我们需要指定键以获得相关的值。
42. What are command line arguments? The arguments/parameters which are sent to the main() function while executing the program from the command prompt or command line. All the arguments sent are in the form of strings only.
42.什么是命令行参数? 从命令提示符或命令行执行程序时发送到main()函数的参数/参数。 发送的所有参数仅采用字符串形式。
43. What is a Friend Class? A class members can gain accessibility over other class member by placing the class declaration prefixed with the keyword ‘friend’ in the destination class.
43.什么是朋友班? 通过在目标类中放置以关键字“ friend”为前缀的类声明,类成员可以获得比其他类成员更高的可访问性。
44. How do you Overload Template Functions? A Template Function may be overloaded either by template methods or ordinary methods of its name, It may be accomplished as follows:
44.如何重载模板功能? 模板函数可以通过模板方法或其名称的普通方法来重载,可以通过以下方式实现:
1. Call an ordinary method that matches exactly. 2. Call a template method that could be created with an exact match. 3. Try normal overloading resolution to ordinary methods and call the one that matches.
1.调用完全匹配的普通方法。 2.调用可以完全匹配的模板方法。 3.尝试对普通方法进行正常的重载解析,然后调用匹配的方法。
45. Enlist STL Algorithms. 1. Retrieve or Non-Mutating Algorithms 2. Mutating Algorithms 3. Sorting Algorithms 4. Set Algorithms 5. Relational Algorithms
45.征募STL算法。 1.检索或非变异算法 2.变异算法 3.排序算法 4.集合算法 5.关系算法
46. Explain try and throw block? The keyword try is used to preface a block of statements that may generate exceptions. This block of statements is known as Try block. When an exception occurs, it is thrown into the catch block using the throw statement.
46.解释一下尝试扔块吗? 关键字try用于在可能产生异常的语句块的开头添加前缀。 该语句块称为Try块。 发生异常时,将使用throw语句将其抛出到catch块中。
47. What is a Virtual Base Class? A Base Class class that has been qualified as Virtual in the inheritance definition. In multiple inheritance, a derived class can inherit the members of a base class via two or more inheritance paths. For a virtual base class, only a single copy of its members will be inherited regardless of the number of inheritance paths between the base class and the derived class.
47.什么是虚拟基类? 在继承定义中已被限定为Virtual的基类。 在多重继承中,派生类可以通过两个或更多继承路径来继承基类的成员。 对于虚拟基类,无论基类与派生类之间的继承路径数量如何,都将仅继承其成员的单个副本。
48. Enlist the Components of Standard Template Library. STL contains several components but the core components are: 1. Iterators 2. Algorithms 3. Containers 4. Functions
48.登记标准模板库的组件。 STL包含几个组件,但核心组件是: 1.迭代器 2.算法 3.容器 4.函数
49. What is Operator Overloading? Operator Overloading basically means to make an Operator behave differently in different instances. Asterisk * is an example of Operator Overloading as it acts as a Pointer as well as a Multiplication operator automatically. Operator overloading is a part of Polymorphism.
49.什么是操作员超载? 运算符重载基本上意味着使运算符在不同情况下的行为有所不同。 星号*是运算符重载的一个示例,因为它自动充当指针和乘法运算符。 运算符重载是多态的一部分。
50. What is Inheritance? It is the process by which Objects of one class acquire the properties of objects of another class. It also supports Hierarchical classification. Inheritance basically provides the concept of Reusability.
50.什么是继承? 这是一类对象获取另一类对象属性的过程。 它还支持层次分类。 继承基本上提供了可重用性的概念。
51. What is RTTI? RTTI represents Runtime Type Information . It determines the type of any variable during execution i.e., during runtime. The RTTI Mechanism contains: 1. Operator Dynamic_Cast 2. Operator Typeid 3. Struct Type_Info
51.什么是RTTI? RTTI表示运行时类型信息。 它确定执行期间(即运行时)任何变量的类型。 RTTI机制包含: 1.运算符Dynamic_Cast 2.运算符Typeid 3.结构Type_Info
52. Enlist Iterators in C++ STL. The Iterators in C++ are as follows: 1. Input 2. Forward 3. Random 4. Output 5. Bidirectional
52.在C ++ STL中注册迭代器。 C ++中的迭代器如下: 1.输入 2.转发 3.随机 4.输出 5.双向
53. What is the role of a Mutable Storage Class Specifier? A constant class object’s member variable can be modified by declaring it using a Specifier of a mutable storage class. It is applicable only for non-static and non-constant member variable of the class.
53.可变存储类说明符的作用是什么? 常量类对象的成员变量可以通过使用可变存储类的指定符声明来进行修改。 它仅适用于该类的非静态和非恒定成员变量。
54. Does C++ Programming Language support Multiple and Multilevel Inheritance? Yes, it does support multiple inheritance and multilevel inheritance.
54. C ++编程语言是否支持多级和多级继承? 是的,它确实支持多重继承和多层继承。
So this was the list of some important C++ interview questions and answers. If you found any information incorrect or missing in above list then please mention it by commenting below.
因此,这是一些重要的C ++面试问题和答案的列表。 如果您在上面的列表中发现任何不正确或缺失的信息,请在下面的评论中提及。
翻译自: https://www.thecrazyprogrammer.com/2015/10/cpp-interview-questions-and-answers.html