20 intermediate level C++ programming interview questions and answers
Interviewing is an important step for both employees and businesses. For employees, you need to answer interview questions well to get hired. Meanwhile, businesses wishing to recruit must create a suitable set of questions to most accurately assess a candidate's capabilities.
In this article, TipsMake.com will summarize the 20 most common C++ programming interview questions at the intermediate level. TipsMake.com hopes that this article will be useful to both intermediate-level programmers looking for jobs and employers.
Question 1: What is the concept of OOP in C++?
Answer: The concept of OOP in C++ is:
- Object
- Class
- Inheritance
- Polymorphism
- Encapsulation
- Abstraction
Object: Anything that exists in the real world is called an object.
Class: A collection of objects is called a class.
Inheritance: The properties of the parent class are inherited into the child class called inheritance.
Polymorphism: It is the ability to exist in many forms.
Encapsulation: Binding code and data together into a single unit.
Abstraction: Hides internal details and exposes functionality to the user.
Question 2: When is the void() return type used?
Answer: The void() return type is used when we do not want to return any value. It specifies that the function does not return a value. A function with a void return type completes its task and then returns control to the caller.
Question 3: In C++, what are call by value and call by reference?
Answer: In call by value method, we pass copies of actual parameters to formal parameters of the function. This means that if there is any change in the value inside the function, it will not affect the actual value.
In method call by reference, the reference or address of the actual parameters is to the formal parameters of the function. This means that any changes in values inside the function will be reflected in the actual values.
Question 4: What is an inline function?
Answer: An inline function, when called, expands by line. When you call this function, the entire code of the inline function will be inserted or replaced at the inline function call.
Syntax:
Inline return-type function-name(parameters) { }
Question 5: What is pointer in C++?
Answer: A pointer is a variable that stores the memory address of another variable. The type of the variable must correspond to the type of the pointer.
Syntax: type *name
Question 6: What is the range resolution operator?
Answer: The range resolution operator is represented as ::.
This operator is used to associate a function definition with a particular class.
The range operator is used for the following purposes:
- To access a global variable when you have a local variable with the same name.
- To define a function outside the class.
Question 7: What result will the C++ program below return?
A: 01
B: 02
C: 012
D: 011
Answer: The result is C, 012. The value of i is 0 and i divided by 5 (i%5) is 0, a division with no remainder, so x is displayed and incremented and i is also incremented go up. Then another 1%5 is a division with remainder so the condition is not met. Similarly, the process will repeat until i is 5. Then, 5%5 is a non-residual division, x is 1 and the values of i and x are again increased to 2. The process will repeat for 6,7,8,9 and up to 10, the division 10%10 is divisible again, the value of x is returned, which is 2.
Question 8: What is a constructor function?
Answer: A constructor is defined as a member function that is called whenever you create an object; it has the same name as the class.
There are two types of constructor functions:
- Default constructor: This function is created automatically and does not accept any arguments.
- Parameterized constructor: In this constructor, it can pass arguments.
Question 9: Define operator overloading and function overloading.
Answer: Operator overloading is an example of compile-time polymorphism. It is the concept of modifying an existing C++ operator without changing its original meaning.
Below is an example of operator overloading:
class A { }; int main() { A a1,a2,a3; a3= a1 + a2; return 0; }
Function overloading is a feature of the C++ language (not found in C). This technique allows using the same name for multiple functions (with the same purpose). But different in parameter data type or number of parameters.
Question 10: How to enter a string with spaces in C++?
Reply:
Question 11: What is the difference between new and malloc?
Reply:
new | malloc |
new is an operator | malloc() is a function |
Say call the constructor function | The malloc function does not call the constructor |
When using new() there is no need to specify a specific memory size | You will have to specify a specific memory size |
The new operator can be overloaded | The malloc() function can never be overloaded |
Question 12: What is operator overloading?
Answer: Operator overloading is a mechanism in which an operator is given a special meaning.
For example, you can overload the "+" operator in a class-like string to concatenate two strings using just "+".
Question 13: What result will the C++ program below return?
A: 0 3
B: 0 8
C: 0 6
D: 0 2
Answer: The result is C, 0 6. In enum, the value of an element is one greater than the previous element. The value of blue is 0 by default and the value of green is 5 so the value of GREAT will automatically become 6.
Question 14: Which of the following is used to return the number of characters in a string?
A: Size
B: Length
C: Both size and length (Both size and length)
D: Name (Name)
Answer: The answer is C, both size and length are used to return the number of characters in a string.
Question 15 : Which answer is correct for the program below:
A: The returned result will be 7.
B: The returned result will be 14.
C: The returned result will be 0.
D: The returned result will be 1.
Answer: The return result will be 7. Pointer 0 has memory address x and if you display the pointer with another operator then it will display the value as 7.
Question 16: Which answer is correct for the program below:
A: The returned result will be 245.
B: The returned result will be 222.
C: The returned result will be 4810.
D: The returned result will be 4812.
Answer : The return will be 4810, because you are passing function references here.
Question 17: What is your function?
Answer : You can define a friend function as a function that can access private, public and protected members of the class. You declare a friend function with the help of the friend keyword. You declare this function inside the class.
Question 18: To find the size of an object or type, which of the following tools do you use?
A: sizeof.
B: malloc.
C: realloc.
D: calloc.
Answer: The answer is A, sizeof. The sizeof operator is used to find the size of an object or type.
Question 19: Which function below is not a member of a class?
A: Static function.
B: Virtual function.
C: Const function.
D: Your jaw.
Answer: The answer is D, your function.
Question 20: What is STL?
Answer: STL stands for standard template library. It is a library of templates that provide common classes and functions.
The components of STL are containers, algorithms, iterators, and function objects.
TipsMake.com hopes that this article will be useful to you!
You should read it
- Questions to interview IT people need to understand
- 15 questions to interview for an extremely 'bad brain' job
- 49 most asked questions that Apple asked in the job interview
- The secret to answering the 15 most frequently asked interview questions
- 15 questions interview the 'hottest' programmers and answer suggestions
- 200 common Java interview questions, with reference answers
- Smart answers when asked in an interview: Do you want to ask any questions?
- What do employers want to know about you when asking this question in an interview?
- 18 'extremely difficult' recruitment questions from Apple
- Ask yourself these 10 questions before the interview to gain more confidence
- 8 employers 'psychological game' to assess the competency of the candidate in the interview
- Three classic questions make the candidate suffer the most when interviewing
Maybe you are interested
How to turn a photo into a painting using the Generative Fill function in Photoshop
How to use the TREND function in Excel
Google Sheets Functions to Simplify Your Budget Spreadsheets
Instructions for using the TRIMRANGE function to clean up Excel tables
How to master numerical data in Google Sheets with the AVERAGE function
Don't buy headphones if they lack this important function!