c++ 经典面试问题及答案_完成C面试问题答案

本文汇总了C++面试中常见的经典问题及详细答案,帮助应聘者准备C++相关的技术面试,涵盖语言特性、算法应用等多个方面。
摘要由CSDN通过智能技术生成

c++ 经典面试问题及答案

The article cover’s most commonly asked interview questions in c++ and a brief explanation of each question.

本文介绍了c ++中最常问到的面试问题,并简要解释了每个问题。

1. What is OOPS?

1.什么是OOPS?

Object-oriented programming is a programming paradigm based on the concept of “objects” of the classes, Objects may contain data in the form of fields and associated code in the form of methods. The objects can access their own procedures and can modify their data fields.

面向对象编程是基于类的“对象”概念的编程范例,对象可以包含字段形式的数据和方法形式的关联代码。 对象可以访问自己的过程,并可以修改其数据字段。

2. What is function overloading, how did it make the lives of C++ programmer better than C programmer?

2.什么是函数重载,它如何使C ++程序员的生活比C程序员更好?

In C++ it’s allowed to make functions with the same name in the same scope. The functions with the same name are called overloaded functions. The difference that must exist between the two functions with the same name is the parameters that are being passed. Function overloading can be done by using different parameter types and changing the number of arguments. C, on the other hand, doesn’t support function overloading which reduces the code quality and readability.

在C ++中,允许在相同范围内使用相同名称创建函数。 具有相同名称的函数称为重载函数。 具有相同名称的两个函数之间必须存在的区别是要传递的参数。 函数重载可以通过使用不同的参数类型并更改参数数量来完成。 另一方面,C不支持函数重载,这会降低代码质量和可读性。

3. How is function overloading achieved?

3.如何实现函数重载?

The program below has “add” function with two different implementations. One for double data type numbers and another for integers. The function has the same name but different parameters so it’s a clear example of function overloading.

下面的程序具有“添加”功能,具有两种不同的实现方式。 一个用于双精度数据类型数字,另一个用于整数。 该函数具有相同的名称,但参数不同,因此是函数重载的一个清晰示例。

#include<bits/stdc++.h>
using namespace std;
int add(int a, int b){//Add Integers
return a+b;
}
double add(double a, double b){//Add Double
return a+b;
}
int main(){
cout<<"Integer Type Numbers after addition : "<<add(1,2)<<"\n";
cout<<"Double Type Numbers after addition : "<<add(1.1,2.2);
}Output:
Integer Type Numbers after addition : 3
Double Type Numbers after addition : 3.3

4. what is dynamic binding?

4.什么是动态绑定?

To Understand Dynamic binding let’s see what are virtual functions and what binding means.

要了解动态绑定,让我们看看什么是虚函数以及绑定的含义。

Binding refers to the process of converting identifiers such as variable and function calls into addresses by the compiler.

绑定是指编译器将诸如变量和函数调用之类的标识符转换为地址的过程。

Virtual Function in c++ is a function which is defined in“Base” class and overridden in “Derived” class. It is made by adding “virtual” keyword in the function definition.Dynamic Binding: In C++ when the compiler is not able to decide which function to ca

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值