Key C++ Programming Principles and Comparisons
1) What is C++? Advantages of C++
C++ is an object-oriented programming language developed by Bjarne Stroustrup. It is an extension of the C language.
Advantages:
- Supports Object-Oriented Programming.
- Code reuse using inheritance.
- Fast execution.
- Data security through encapsulation.
- Portable language.
- Supports function and operator overloading.
2) Difference Between Procedural and Object-Oriented Programming
| Procedural Programming | Object-Oriented Programming |
|---|---|
| Program divided into functions | Program divided into objects |
| Top-down approach | Bottom-up approach |
| Less data security | More data security |
| Example: C | Example: C++ |
3) Six Advantages of OOP
- Data hiding provides security.
- Code reusability using inheritance.
- Easy program maintenance.
- Reduces program complexity.
- Easy debugging.
- Real-world modeling possible.
4) Explain Classes and Objects
Class: A class is a collection of data members and member functions.
class Student {
int roll;
void display();
};Object: An object is an instance of a class.
Student s1;
5) Resemblance Between Arrays and Pointers
- Both store memory addresses.
- Array name acts like a pointer.
- Pointer arithmetic can be used with arrays.
- Both access elements using indexing.
6) Why References Are Used
References are used to:
- Pass arguments by reference.
- Avoid copying data.
- Modify the original variable.
- Improve performance.
7) Difference Between Class and Structure
| Class | Structure |
|---|---|
| Members private by default | Members public by default |
| Used in OOP | Used for simple data grouping |
8) Runtime and Compile-Time Polymorphism
Compile-Time Polymorphism
Achieved during compilation. Examples:
- Function overloading
- Operator overloading
Runtime Polymorphism
Achieved during execution. Example:
- Virtual function overriding.
9) Operator Function and Syntax
An operator function is used to overload operators.
Syntax:
return_type operator op(arguments) {
// body
}Example: int operator+(int a);
10) Operator Function: Member vs. Friend
| Member Function | Friend Function |
|---|---|
| Belongs to class | Not a member of class |
| Uses object directly | Uses arguments |
| Called using object | Called normally |
English with a size of 2.99 KB