C++ Programming Language
Table of content:
- A Brief Intro To C++
- The Timeline Of C++
- Importance Of C++
- Versions Of C++ Language
- Comparison With Other Popular Programming Languages
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Are Variables In C++?
- Declaration & Definition Of Variables In C++
- Variable Initialization In C++
- Rules & Regulations For Naming Variables In C++ Language
- Different Types Of Variables In C++
- Different Types of Variable Initialization In C++
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Are Primitive Data Types In C++?
- Derived Data Types In C++
- User-Defined Data Types In C++
- Abstract Data Types In C++
- Data Type Modifiers In C++
- Declaring Variables With Auto Keyword
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- Structure Of C++ Program: Components
- Compilation & Execution Of C++ Programs | Step-by-Step Explanation
- Structure Of C++ Program With Example
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What is Typedef in C++?
- The Role & Applications of Typedef in C++
- Basic Syntax for typedef in C++
- How Does typedef Work in C++?
- How to Use Typedef in C++ With Examples? (Multiple Data Types)
- The Difference Between #define & Typedef in C++
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Are Strings In C++?
- Types Of Strings In C++
- How To Declare & Initialize C-Style Strings In C++ Programs?
- How To Declare & Initialize Strings In C++ Using String Keyword?
- List Of String Functions In C++
- Operations On Strings Using String Functions In C++
- Concatenation Of Strings In C++
- How To Convert Int To Strings In C++
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Is String Concatenation In C++?
- How To Concatenate Two Strings In C++ Using The ‘+' Operator?
- String Concatenation Using The strcat( ) Function
- Concatenation Of Two Strings In C++ Using Loops
- String Concatenation Using The append() Function
- C++ String Concatenation Using The Inheritance Of Class
- Concatenate Two Strings In C++ With The Friend and strcat() Functions
- Why Do We Need To Concatenate Two Strings?
- How To Reverse Concatenation Of Strings In C++?
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Is Find In String C++?
- What Is A Substring?
- How To Find A Substring In A String In C++?
- How To Find A Character In String C++?
- Find All Substrings From A Given String In C++
- Index Substring In String In C++ From A Specific Start To A Specific Length
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Are Pointers In C++?
- Pointer Declaration In C++
- How To Initialize And Use Pointers In C++?
- Different Types Of Pointers In C++
- References & Pointers In C++
- Arrays And Pointers In C++
- String Literals & Pointers In C++
- Pointers To Pointers In C++ (Double Pointers)
- Arithmetic Operation On Pointers In C++
- Advantages Of Pointers In C++
- Some Common Mistakes To Avoid With Pointers In Cpp
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- Understanding Pointers In C++
- What Is Pointer To Object In C++?
- Declaration And Use Of Object Pointers In C++
- Advantages Of Pointer To Object In C++
- Pointer To Objects In C++ With Arrow Operator
- An Array Of Objects Using Pointers In C++
- Base Class Pointer For Derived Class Object In C++
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Is 'This' Pointer In C++?
- Defining ‘this’ Pointer In C++
- Example Of 'this' Pointer In C++
- Describing The Constness Of 'this' Pointer In C++
- Important Uses Of 'this' Pointer In C++
- Method Chaining Using 'this' Pointer In C++
- C++ Programs To Show Application Of 'This' Pointer
- How To Delete The ‘this’ Pointer In C++?
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What is Reference?
- What is Pointer?
- Comparison Table Of C++ Pointer Vs. Reference
- Differences Between Reference And Pointer: A Detailed Explanation
- Why Are References Less Powerful Than Pointers?
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- How To Declare A 2D Array In C++?
- C++ Multi-Dimensional Arrays
- Ways To Initialize A 2D Array In C++
- Methods To Dynamically Allocate A 2D Array In C++
- Accessing/ Referencing Two-Dimensional Array Elements
- How To Initialize A Two-Dimensional Integer Array In C++?
- How To Initialize A Two-Dimensional Character Array?
- How To Enter Data In Two-Dimensional Array In C++?
- Conclusion
- Frequently Asked Questions
Table of content:
- What Are Arrays Of Strings In C++?
- Different Ways To Create String Arrays In C++
- How To Access The Elements Of A String Array In C++?
- How To Convert Char Array To String?
- Conclusion
- Frequently Asked Questions
Table of content:
- What is Memory Allocation in C++?
- The “new" Operator In C++
- The "delete" Operator In C++
- Dynamic Memory Allocation In C++ | Arrays
- Dynamic Memory Allocation In C++ | Objects
- Deallocation Of Dynamic Memory
- Dynamic Memory Allocation In C++ | Uses
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Is A Substring In C++ (Substr C++)?
- Example For Substr In C++
- Points To Remember For Substr In C++
- Important Applications Of substr() Function
- How to Get a Substring Before a Character?
- Print All Substrings Of A Given String
- Print Sum Of All Substrings Of A String Representing A Number
- Print Minimum Value Of All Substrings Of A String Representing A Number
- Print Maximum Value Of All Substrings Of A String Representing A Number
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Is Operator In C++?
- Types Of Operators In C++ With Examples
- What Are Arithmetic Operators In C++?
- What Are Assignment Operators In C++?
- What Are Relational Operators In C++?
- What Are Logical Operators In C++?
- What Are Bitwise Operators In C++?
- What Is Ternary/ Conditional Operator In C++?
- Miscellaneous Operators In C++
- Precedence & Associativity Of Operators In C++
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Is The New Operator In C++?
- Example To Understand New Operator In C++
- The Grammar Elements Of The New Operator In C++
- Storage Space Allocation
- How Does The C++ New Operator Works?
- What Happens When Enough Memory In The Program Is Not Available?
- Initializing Objects Allocated With New Operator In C++
- Lifetime Of Objects Allocated With The New Operator In C++
- What Is The Delete Operator In C++?
- Difference Between New And Delete Operator In C++
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- Types Of Overloading In C++
- What Is Operator Overloading In C++?
- How To Overload An Operator In C++?
- Overloadable & Non-overloadable Operators In C++
- Unary Operator Overloading In C++
- Binary Operator Overloading In C++
- Special Operator Overloading In C++
- Rules For Operator Overloading In C++
- Advantages And Disadvantages Of Operator Overloading In C++
- Function Overloading In C++
- What Is the Difference Between Operator Functions and Normal Functions?
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Are Operators In C++?
- Introduction To Logical Operators In C++
- Types Of Logical Operators In C++ With Example Program
- Logical AND (&&) Operator In C++
- Logical NOT(!) Operator In C++
- Logical Operator Precedence And Associativity In C++
- Relation Between Conditional Statements And Logical Operators In C++
- C++ Relational Operators
- Conclusion
- Frequently Asked Important Interview Questions:
- Test Your Skills: Quiz Time
Table of content:
- Different Type Of C++ Bitwise Operators
- C++ Bitwise AND Operator
- C++ Bitwise OR Operator
- C++ Bitwise XOR Operator
- Bitwise Left Shift Operator In C++
- Bitwise Right Shift Operator In C++
- Bitwise NOT Operator
- What Is The Meaning Of Set Bit In C++?
- What Does Clear Bit Mean?
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- Types of Comments in C++
- Single Line Comment In C++
- Multi-Line Comment In C++
- How Do Compilers Process Comments In C++?
- C- Style Comments In C++
- How To Use Comment In C++ For Debugging Purposes?
- When To Use Comments While Writing Codes?
- Why Do We Use Comments In Codes?
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Are Storage Classes In Cpp?
- What Is The Scope Of Variables?
- What Are Lifetime And Visibility Of Variables In C++?
- Types of Storage Classes in C++
- Automatic Storage Class In C++
- Register Storage Class In C++
- Static Storage Class In C++
- External Storage Class In C++
- Mutable Storage Class In C++
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- Decision Making Statements In C++
- Types Of Conditional Statements In C++
- If-Else Statement In C++
- If-Else-If Ladder Statement In C++
- Nested If Statements In C++
- Alternatives To Conditional If-Else In C++
- Switch Case Statement In C++
- Jump Statements & If-Else In C++
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Is A Switch Statement/ Switch Case In C++?
- Rules Of Switch Case In C++
- How Does Switch Case In C++ Work?
- The break Keyword In Switch Case C++
- The default Keyword In C++ Switch Case
- Switch Case Without Break And Default
- Advantages & Disadvantages of C++ Switch Case
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Is A For Loop In C++?
- Syntax Of For Loop In C++
- How Does A For Loop In C++ Work?
- Examples Of For Loop Program In C++
- Ranged Based For Loop In C++
- Nested For Loop In C++
- Infinite For Loop In C++
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Is A While Loop In C++?
- Parts Of The While Loop In C++
- C++ While Loop Program Example
- How Does A While Loop In C++ Work?
- What Is Pre-checking Process Or Entry-controlled Loop?
- When Are While Loops In C++ Useful?
- Example C++ While Loop Program
- What Are Nested While Loops In C++?
- Infinite While Loop In C++
- Alternatives To While Loop In C++
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Are Loops & Its Types In C++?
- What Is A Do-While Loop In C++?
- Do-While Loop Example In C++ To Print Numbers
- How Does A Do-While Loop In C++ Work?
- Various Components Of The Do-While Loop In C++
- Example 2: Adding User-Input Positive Numbers With Do-While Loop
- C++ Nested Do-While Loop
- C++ Infinitive Do-while Loop
- What is the Difference Between While Loop and Do While Loop in C++?
- When To Use A Do-While Loop?
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Are 2D Vectors In C++?
- How To Declare 2D Vector In C++?
- How To Initialize 2D Vector In C++?
- C++ Program Examples For 2D Vectors
- How To Access & Modify 2D Vector Elements In C++?
- Methods To Traverse, Manipulate & Print 2D Vectors In C++
- Adding Elements To 2-D Vector Using push_back() Function
- Removing Elements From Vector In C++ Using pop_back() Function
- Creating 2D Vector In C++ With User Input For Size Of Column & Row
- Advantages of 2D Vectors Over Traditional Arrays
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- How To Print A Vector In C++ By Overloading Left Shift (<<) Operator?
- How To Print Vector In C++ Using Range-Based For-Loop?
- Print Vector In C++ With Comma Separator
- Printing Vector In C++ Using Indices (Square Brackets/ Double Brackets & at() Function)
- How To Print A Vector In C++ Using std::copy?
- How To Print A Vector In C++ Using for_each() Function?
- Printing C++ Vector Using The Lambda Function
- How To Print Vector In C++ Using Iterators?
- Conclusion
- Frequently Asked Questions
Table of content:
- Definition Of C++ Find In Vector
- Using The std::find() Function
- How Does find() In Vector C++ Function Work?
- Finding An Element By Custom Comparator Using std::find_if() Function
- Use std::find_if() With std::distance()
- Element Find In Vector C++ Using For Loop
- Using The find_if_not Function
- Find Elements With The Linear Search Approach
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is Sort() Function In C++?
- Sort() Function In C++ From Standard Template Library
- Exceptions Of Sort() Function/ Algorithm In C++
- The Stable Sort() Function In C++
- Partial Sort() Function In C++
- Sorting In Ascending Order With Sort() Function In C++
- Sorting In Descending Order With Sort Function In C++
- Sorting In Desired Order With Custom Comparator Function & Sort Function In C++
- Sorting Elements In Desired Order Using Lambda Expression & Sort Function In C++
- Types of Sorting Algorithms In C++
- Advanced Sorting Algorithms In C++
- How Does the Sort() Function Algorithm Work In C++?
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is Function Overloading In C++?
- Ways Of Function Overloading In C++
- Function Overloading In C++ Using Different Types Of Parameters
- Function Overloading In C++ With Different Number Of Parameters
- Function Overloading In C++ Using Different Sequence Of Parameters
- How Does Function Overloading In C++ Work?
- Rules Of Function Overloading In C++
- Why Is Function Overloading Used?
- Types Of Function Overloading Based On Time Of Resolution
- Causes Of Function Overloading In C++
- Ambiguity & Function Overloading In C++
- Advantages Of Function Overloading In C++
- Disadvantages Of Function Overloading In C++
- Operator Overloading In C++
- Function Overriding In C++
- Difference Between Function Overriding & Function Overloading In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is An Inline Function In C++?
- How To Define The Inline Function In C++?
- How Does Inline Function In C++ Work?
- The Need For An Inline Function In C++
- Can The Compiler Ignore/ Reject Inline Function In C++ Programs?
- Normal Function Vs. Inline Function In C++
- Classes & Inline Function In C++
- Understanding Inline, __inline, And __forceinline Functions In C++
- When To Use An Inline Function In C++?
- Advantages Of Inline Function In C++
- Disadvantages Of Inline Function In C++
- Why Not Use Macros Instead Of An Inline Function In C++?
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Is Static Data Member In C++?
- How To Declare Static Data Members In C++?
- How To Initialize/ Define Static Data Member In C++?
- Ways To Access A Static Data Member In C++
- What Are Static Member Functions In C++?
- Example Of Member Function & Static Data Member In C++
- Practical Applications Of Static Data Member In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is A Constant In C++?
- Ways To Define Constant In C++
- What Are Literals In C++?
- Pointer To A Constant In C++
- Constant Function Arguments In C++
- Constant Member Function Of Class In C++
- Constant Data Members In C++
- Object Constant In C++
- Conclusion
- Frequently Asked Questions(FAQ)
Table of content:
- What Is Friend Function In C++?
- Declaration Of Friend Function In C++ With Example
- Characteristics Of Friend Function In C++
- Global Friend Function In C++ (Global Function As Friend Function )
- Member Function Of Another Class As Friend Function In C++
- Function Overloading Using Friend Function In C++
- Advantages & Disadvantages Of Friend Function in C++
- What Is A C++ Friend Class?
- A Function Friendly To Multiple Classes
- C++ Friend Class Vs. Friend Function In C++
- Some Important Points About Friend Functions And Classes In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is Function Overriding In C++?
- The Working Mechanism Of Function Overriding In C++
- Real-Life Example Of Function Overriding In C++
- Accessing Overriding Function In C++
- Accessing Overridden Function In C++
- Function Call Binding With Class Objects | Function Overriding In C++
- Function Call Binding With Base Class Pointers | Function Overriding In C++
- Advantages Of Function Overriding In C++
- Variations In Function Overriding In C++
- Function Overloading In C++
- Function Overloading Vs Function Overriding In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- Errors In C++
- What Is Exception Handling In C++?
- Exception Handling In C++ Program Example
- C++ Exception Handling: Basic Keywords
- The Need For C++ Exception Handling
- C++ Standard Exceptions
- C++ Exception Classes
- User-Defined Exceptions In C++
- Advantages & Disadvantages Of C++ Exception Handling
- Conclusion
- Frequently Asked Questions
Table of content:
- What Are Templates In C++ & How Do They Work?
- Types Of Templates In C++
- What Are Function Templates In C++?
- C++ Template Functions With Multiple Parameters
- C++ Template Function Overloading
- What Are Class Templates In C++?
- Defining A Class Member Outside C++ Template Class
- C++ Template Class With Multiple Parameters
- What Is C++ Template Specialization?
- How To Specify Default Arguments For Templates In C++?
- Advantages Of C++ Templates
- Disadvantages Of C++ Templates
- Difference Between Function Overloading And Templates In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- Structure
- Structure Declaration
- Initialization of Structure
- Copying and Comparing Structures
- Array of Structures
- Nested Structures
- Pointer to a Structure
- Structure as Function Argument
- Self Referential Structures
- Class
- Object Declaration
- Accessing Class Members
- Similarities between Structure and Class
- Which One Should You Choose?
- Key Difference Between a Structure and Class
- Summing Up
- Test Your Skills: Quiz Time
Table of content:
- What Is A Class And Object In C++?
- What Is An Object In C++?
- How To Create A Class & Object In C++? With Example
- Access Modifiers & Class/ Object In C++
- Member Functions Of A Class In C++
- How To Access Data Members And Member Functions?
- Significance Of Class & Object In C++
- What Are Constructors In C++ & Its Types?
- What Is A Destructor Of Class In C++?
- An Array Of Objects In C++
- Object In C++ As Function Arguments
- The this (->) Pointer & Classes In C++
- The Need For Semicolons At The End Of A Class In C++
- Difference Between Structure & Class In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- What Are Static Members In C++?
- Static Member Functions in C++
- Ways To Call Static Member Function In C++
- Properties Of Static Member Function In C++
- Need Of Static Member Functions In C++
- Regular Member Function Vs. Static Member Function In C++
- Limitations Of Static Member Functions In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is Constructor In C++?
- Characteristics Of A Constructor In C++
- Types Of Constructors In C++
- Default Constructor In C++
- Parameterized Constructor In C++
- Copy Constructor In C++
- Dynamic Constructor In C++
- Benefits Of Using Constructor In C++
- How Does Constructor In C++ Differ From Normal Member Function?
- Constructor Overloading In C++
- Constructor For Array Of Objects In C++
- Constructor In C++ With Default Arguments
- Initializer List For Constructor In C++
- Dynamic Initialization Using Constructor In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is A Constructor In C++?
- What Is Constructor Overloading In C++?
- Dеclaration Of Constructor Ovеrloading In C++
- Condition For Constructor Overloading In C++
- How Constructor Ovеrloading In C++ Works?
- Examples Of Constructor Overloading In C++
- Lеgal & Illеgal Constructor Ovеrloading In C++
- Types Of Constructors In C++
- Characteristics Of Constructors In C++
- Advantage Of Constructor Overloading In C++
- Disadvantage Of Constructor Overloading In C++
- Conclusion
- Frеquеntly Askеd Quеstions
Table of content:
- What Is A Destructor In C++?
- Rules For Defining A Destructor In C++
- When Is A Destructor in C++ Called?
- Order Of Destruction In C++
- Default Destructor & User-Defined Destructor In C++
- Virtual Destructor In C++
- Pure Virtual Destructor In C++
- Key Properties Of Destructor In C++ You Must Know
- Explicit Destructor Calls In C++
- Destructor Overloading In C++
- Difference Between Normal Member Function & Destructor In C++
- Important Uses Of Destructor In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is A Constructor In C++?
- What Is A Destructor In C++?
- Difference Between Constructor And Destructor In C++
- Constructor In C++ | A Brief Explanation
- Destructor In C++ | A Brief Explanation
- Difference Between Constructor And Destructor In C++ Explained
- Order Of Calling Constructor And Destructor In C++ Classes
- Conclusion
- Frequently Asked Questions
- Test Your Skills: Quiz Time
Table of content:
- What Is Type Conversion In C++?
- What Is Type Casting In C++?
- Types Of Type Conversion In C++
- Implicit Type Conversion (Coercion) In C++
- Explicit Type Conversion (Casting) In C++
- Advantages Of Type Conversion In C++
- Disadvantages Of Type Conversion In C++
- Difference Between Type Casting & Type Conversion In C++
- Application Of Type Casting In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is A Copy Constructor In C++?
- Characteristics Of Copy Constructors In C++
- Types Of Copy Constructors In C++
- When Do We Call The Copy Constructor In C++?
- When Is A User-Defined Copy Constructor Needed In C++?
- Types Of Constructor Copies In C++
- Can We Make The Copy Constructor In C++ Private?
- Assignment Operator Vs Copy Constructor In C++
- Example Of Class Where A Copy Constructor Is Essential
- Uses Of Copy Constructors In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- Why Do You Need Object-Oriented Programming (OOP) In C++?
- OOPs Concepts In C++ With Examples
- The Class OOPs Concept In C++
- The Object OOPs Concept In C++
- The Inheritance OOPs Concept In C++
- Polymorphism OOPs Concept In C++
- Abstraction OOPs Concept In C++
- Encapsulation OOPs Concept In C++
- Other Features Of OOPs In C++
- Benefits Of OOP In C++ Over Procedural-Oriented Programming
- Disadvantages Of OOPS Concept In C++
- Why Is C++ A Partial OOP Language?
- Conclusion
- Frequently Asked Questions
Table of content:
- Introduction To Abstraction In C++
- Types Of Abstraction In C++
- What Is Data Abstraction In C++?
- Understanding Data Abstraction In C++ Using Real Life Example
- Ways Of Achieving Data Abstraction In C++
- What Is An Abstract Class?
- Advantages Of Data Abstraction In C++
- Use Cases Of Data Abstraction In C++
- Encapsulation Vs. Abstraction In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is Encapsulation In C++?
- How Does Encapsulation Work In C++?
- Types Of Encapsulation In C++
- Why Do We Need Encapsulation In C++?
- Implementation Of Encapsulation In C++
- Access Specifiers & Encapsulation In C++
- Role Of Access Specifiers In Encapsulation In C++
- Member Functions & Encapsulation In C++
- Data Hiding & Encapsulation In C++
- Features Of Encapsulation In C++
- Advantages & Disadvantages Of Encapsulation In C++
- Difference Between Abstraction and Encapsulation In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is Inheritance In C++?
- What Are Child And Parent Classes?
- Syntax And Structure Of Inheritance In C++
- Implementing Inheritance In C++
- Importance Of Inheritance In C++
- Types Of Inheritance In C++
- Visibility Modes Of Inheritance In C++
- Access Modifiers & Inheritance In C++
- How To Make A Private Member Inheritable?
- Member Function Overriding In Inheritance In C++
- The Diamond Problem | Inheritance In C++ & Ambiguity
- Ways To Avoid Ambiguity Inheritance In C++
- Why & When To Use Inheritance In C++?
- Advantages Of Inheritance In C++
- The Disadvantages Of Inheritance In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is Hybrid Inheritance In C++?
- Importance Of Hybrid Inheritance In Object Oriented Programming
- Example Of Hybrid Inheritance In C++: Using Single and Multiple Inheritance
- Example Of Hybrid Inheritance In C++: Using Multilevel and Hierarchical Inheritance
- Real-World Applications Of Hybrid Inheritance In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is Multiple Inheritance In C++?
- Examples Of Multiple Inheritance In C++
- Ambiguity Problem In Multiple Inheritance In C++
- Ambiguity Resolution In Multiple Inheritance In C++
- The Diamond Problem In Multiple Inheritance In C++
- Visibility Modes In Multiple Inheritance In C++
- Advantages & Disadvantages Of Multiple Inheritance In C++
- Multiple Inheritance Vs. Multilevel Inheritance In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is Multilevel Inheritance In C++?
- Block Diagram For Multilevel Inheritance In C++
- Multilevel Inheritance In C++ Example
- Constructor & Multilevel Inheritance In C++
- Use Cases Of Multilevel Inheritance In C++
- Multiple Vs Multilevel Inheritance In C++
- Advantages & Disadvantages Of Multilevel Inheritance In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is Hierarchical Inheritance In C++?
- Example 1: Hierarchical Inheritance In C++
- Example 2: Hierarchical Inheritance In C++
- Impact of Visibility Modes In Hierarchical Inheritance In C++
- Advantages And Disadvantages Of Hierarchical Inheritance In C++
- Use Cases Of Hierarchical Inheritance In C++
- Conclusion
- Frequently Asked Questions
Table of content:
- What Are Access Specifiers In C++?
- Types Of Access Specifiers In C++
- Public Access Specifiers In C++
- Private Access Specifier In C++
- Protected Access Specifier In C++
- The Need For Access Specifiers In C++
- Combined Example For All Access Specifiers In C++
- Best Practices For Using Access Specifiers In C++
- Why Can't Private Members Be Accessed From Outside A Class?
- Conclusion
- Frequently Asked Questions
Table of content:
- What Is The Diamond Problem In C++?
- Example Of The Diamond Problem In C++
- Resolution Of The Diamond Problem In C++
- Virtual Inheritance To Resolve Diamond Problem In C++
- Scope Resolution Operator To Resolve Diamond Problem In C++
- Conclusion
- Frequently Asked Questions
How To Print A Vector In C++ | 8 Methods Explained With Examples

Vectors are similar to dynamic arrays, with the main difference being that the former are automatically resizable. Vector elements are stored in contiguous, i.e., continuous memory locations. This makes it easier to access and traverse through the vector elements using iterators or pointers. When the elements are added or removed from a vector, it is called insertion or deletion. To see the changes in the vector, we may need to print the vector elements.
In this article, we'll explore different methods of how to print a vector in C++, ranging from basic to advanced techniques.
Printing the elements of a vector is a common task in programming. There are multiple methods to get this done, as mentioned before. We have detailed each of these methods in the sections below with the help of C++ programs examples.
How To Print A Vector In C++ By Overloading Left Shift (<<) Operator?
Operator Overloading in C++ allows us to extend the abilities of an operator and give special meaning to it while keeping its original meaning intact. It can have the same name or symbol but more than one execution behavior or use.
The output streams use the insertion operator ‘<<’ for standard types. To print all elements of the vector by iterating one by one, we need to overload the ‘<<’ operator. By overloading the << operator as a template function in the global scope, the cout can be made to accept a vector element after the ‘<<’ operator.
Here is an example of how to print a vector in C++ by overloading << operator:
// C++ program to print a vector using << overloading
#include <iostream>
#include <vector>
using namespace std;
//template function to overload << operator
template <typename ele_type> ostream& operator<<(ostream& os, const vector<ele_type>& vect_name){
// itr is iterator for each element traversal
for (auto itr : vect_name){
os << itr << " ";}
return os;}
int main(){
// vector containing Character elements
vector<char> V = { 'U' , 'N', 'S', 'T', 'O', 'P' };
cout << V << endl;
return 0;
}
Output:
U N S T O P
Explanation:
- The operator << is a template function that takes 2 arguments, the output stream (‘ostream& os) and the vector (‘constant vector<ele_type>& vector’). Here ele_type represents the type of elements in the vector.
- This function contains a for loop which iterates over each vector element, printed to the output stream, followed by a space.
- The function then returns the output stream to the calling function.
- In the main function, a vector V is initialized with character elements and object cout is used to print the elements of vector V by calling the operator << function.
How To Print Vector In C++ Using Range-Based For-Loop?
The range-based for-loop method is also another method that is widely used for printing vector elements in C++. We use an iterator to iterate through the full range or length of the vector. The iterator only iterates until the last element of the vector and therefore is dependent upon the vector size or range. This is hence referred to as the process of using range-based for-loop.
Given below is a sample code of how to print a vector in C++ using range-based for-loop:
// C++ program to print vector using range-based for loop
#include <iostream>
#include <vector>
int main() {
std::vector<int> myVector = {1, 2, 3, 4, 5};
std::cout << "Vector elements: ";
for (const auto& element : myVector) {
std::cout << element << " ";
}
std::cout << std::endl;
return 0;
}
Output:
Vector elements: 1 2 3 4 5
Explanation:
- We start by including the necessary header files. Here, iostream is required for input/output operations like std::cout, and vector is needed for using the std::vector container.
- In the main function, we declare a vector of integers named myVector and initialize it with five elements, 1, 2, 3, 4, and 5.
- We use std::cout to print the message Vector elements: on the console. This text will be displayed before the vector elements.
- Next, the program starts with the range-based for-loop.
- The loop iterates over the elements of myVector. The const auto& element declares a loop variable element, which will be assigned the value of each element in the vector during each iteration.
- Inside the loop, we use std::cout again to print the value of an element. Since the element represents each element in the vector during each iteration, this statement prints each element of the vector on the console, followed by a space.
- After the for-loop, we use std::cout to print std::endl, which adds a new line to move the cursor to the next line in the console. This ensures that the next output appears on a new line.
- Finally, the return 0; statement indicates that the main function has been successfully executed, and the program is terminating with no errors (returning 0 indicates successful completion).
Print Vector In C++ With Comma Separator
To avoid the overloading method, we can print the elements by making a custom separator function to print the elements by separating them using a separator. A comma operator (,) is a type of separator that is used while declaring, initializing variables, or defining elements in an array, vector, list, etc. Here we use the comma operator while printing.
Here is an example of how to print a vector in C++ using a separator function:
// C++ program to print vector using comma as separator
#include <iostream>
#include <vector>
using namespace std;
template <typename ele_type>
// print() function takes input arguments
// vector and the separator string
void print(const vector<ele_type>& V,string sept = " ")
{
// Iterating over vector elements
for (auto element : V) {
cout << element << sept;}
cout << endl;
}
int main(){
// declaring and initializing string vector
vector<string> V{ "Print", "Vector", "Using", "Comma", "Separator"};
// Printing all vector elements with ',' separator
print(V , ",");
return 0;
}
Output:
Print, Vector, Using, Comma, Separator,
Explanation:
- The print() is a template function that takes 2 arguments, i.e., a separator string (string sept) and the vector (constant vector<ele_type>& vector). Here ele_type represents the type of elements in the vector.
- This function contains a for loop which iterates over each vector element, printed to an output stream, followed by a comma (,) stored in a sept separator.
- The function then returns the output stream to the calling function.
- In the main function, a vector V is initialized with string elements and object cout is used to print the elements of vector V by calling the print() function.
Printing Vector In C++ Using Indices (Square Brackets/ Double Brackets & at() Function)
The simplest way to iterate through and print the vector elements is to use a simple for loop and access its elements using the at() function or index operator (denoted by []) with the corresponding index.
The at() function and the [] operator return the element present at the index mentioned inside the () and [] brackets, respectively. Given in the code snippet below is an example of how to print a vector in C++ using indices.
Code:
// C++ program to print vectors using indices
#include <iostream>
#include <vector>
using namespace std;
template <typename ele_type>
// print() function takes a vector as an input argument
void print(const vector<ele_type>& V){
for (int i = 0; i < V.size(); i++) {
// Using at function
// cout<< V.at(i) << ' ';
//Using [] operator
cout << V[i] << ' ';}
}
int main(){
vector<float> V = { 1.1, 2.2, 3.3, 4.4, 5.5 };
print(V);
return 0;
}
Output:
1.1 2.2 3.3 4.4 5.5
Explanation:
In the C++ program above,
- We begin by defining the template function print() that takes vector (const vector<ele_type>& vector) as an input argument. Here the ele_type represents the type of elements in the vector.
- The function uses a simple for loop, which iterates over each vector element using a [] operator where the integer variable, i, denotes the current position.
- Then in the main function, we initialize a vector V with float elements.
- Next, the vector object cout is used to print the elements of vector V with a space.
How To Print A Vector In C++ Using std::copy?
The std::copy function is a function provided by the C++ Algorithm Library, which is used to copy a range of elements of a container from the present memory location to a new memory location. Or to a new container present at different memory locations. While printing a vector, it can be used to copy the vector contents to output stream cout using iterator ostream_iterator.
The code snippet below is an example of how to print a vector in C++ using the std::copy function:
// C++ program to print vectors using the copy function
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
using namespace std;
template <typename ele_type>
// print() function takes a vector as an input argument
void print(const vector<ele_type>& V){
copy(V.begin(),V.end(),ostream_iterator<ele_type>(cout, " "));
}
int main(){
// Vector containing character elements
vector<char> V = { 'U' , 'N', 'S', 'T', 'O', 'P' };
print(V);
return 0;
}
Output:
U N S T O P
Explanation:
- The print() is a template function that takes a vector as input (const vector<ele_type>& vector) argument. And ele_type represents the type of elements in the vector.
- The function contains a copy algorithm that takes the V.begin() and V.end(), i.e., the beginning and the ending iterator, respectively, as input arguments.
- It also takes ostream_iterator<ele_type>(cout, " ")) as the third input argument where the “ “ is a space separator.
- The copy algorithm copies each vector element to ostream cout using the ostream_iterator.
- We then declare and initialize a vector V in the main function with the values U, N, S, T, O, P.
- The print function is then used to print the output on the console, and the program terminates with a return 0.
Check this out- Boosting Career Opportunities For Engineers Through E-School Competitions
How To Print A Vector In C++ Using for_each() Function?
The use of the for_each() function also provides an elegant way to print the vector elements. It takes three input arguments, a start and end iterator, which defines or informs the function about the range of the vector that is to print. And then applies the function provided as the third input parameter to each element of the vector in the given range.
Let’s understand how to print a vector in C++ using the for-each() function with the help of an example given below.
Code:
// C++ program to print vector using for_each() function
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
//print function takes one input argument
// or one vector element and
//prints it followed by a space
void print(const string &i) {
cout << i << ' ';}
void print_vector(vector<string> const &V) {
//begin() and end() function point to start and end point
//of the range of vector elements to be printed
//print function is applied on each element in the range
for_each(V.begin(), V.end(),print);}
int main(){
vector<string> V = { "A", "Vector", "Is", "Printed" };
print_vector(V);
return 0;
}
Output:
A Vector Is Printed
Explanation:
- In this code, we use the for_each() function, present in the print_vector function, and it takes three input arguments, two iterators, and a function.
- The two iterators V.begin() and V.end(), act as the beginning and the ending iterator, respectively, which define the range of vector to be printed.
- The print function is the third input argument applied to each vector element.
- When the print function is called, it takes a vector element as the only input parameter and prints it followed by a space. This repeats for each element.
- In the main function, we declare and initialize the vector V, and then it is passed onto the print_vector function.
Printing C++ Vector Using The Lambda Function
A lambda function is a feature provided in modern C++ that is from C++ 11 onwards. These functions are the kind of separate functions that are or can be treated as any other class object or struct. In simple words, it can be used to just read the value of a vector variable or element without making any changes to it or accessing any other information related to it.
We can use the lambda expression on each vector element to print the element without providing the element type. We will also take the help of the for_each() function as we have used in the above example.
Here is an example of how to print a vector in C++ using the Lambda function:
// C++ program to print vector elements
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
// Vector containing character elements
vector<char> V = { 'U' , 'N', 'S', 'T', 'O', 'P' };
// Printing vector elements
for_each(V.begin(), V.end(), [](const auto& element)
{ //printing using " "
cout << element << " ";
});
return 0;
}
Output:
U N S T O P
Explanation:
In this code, we begin by declaring and initializing vector V with character elements.
- We then use the lambda function that is defined in the square sequence containers [] and take const auto& element as an input argument.
- Here the keyword auto automatically interprets the element type of the vector and prints them with a space “ ” in between using the cout statement.
- The for_each algorithm is used for iteration over each vector element and takes V.begin() and V.end() as the beginning and the ending iterator, respectively.
- It also takes the lambda function as the third input argument.
How To Print Vector In C++ Using Iterators?
Iterators are markers or pointers that point to the specific position of an element in a vector. Usually, we use constant iterators to get the start and end point of the vector, and another for loop iterates that iterates over each element in the defined range.
Here is an example of how to print an iterator of a vector in C++:
// C++ program to print vectors using iterators
#include <iostream>
#include <vector>
using namespace std;
template <typename ele_type>
// print() function takes a vector as an input argument
void print( const vector<ele_type> &V){
//iterator itr points to address of a vector element .
//dereferenced using * operator
// and printed followed by a space
for (auto itr = V.cbegin(); itr != V.cend(); itr++) {
cout << *itr << ' ';}
}
int main(){
vector<char> V = { '#', 'U', 'N', 'S', 'T', 'O', 'P', 'P', 'A', 'B', 'L', 'E'};
print(V);
return 0;
}
Output:
# U N S T O P P A B L E
Explanation:
- The print() is a template function that takes as input (const vector<ele_type>& vector) argument, where ele_type represents the type of elements in the vector.
- This function uses a for loop, which iterates over each vector element using the iterator, itr that points to the address of a vector element.
- The itr is dereferenced using the asterisk operator (*) and printed followed by a space, using cout.
- The constant iterators, cbegin() and cend(), define the starting and end points of the range of the vector to be printed.
- In the main function, we declare and initialize vector V with character elements. We then call the print() function to print the elements on the console.
Conclusion
Vectors are similar to dynamic arrays but are automatically resizable. That is, since vector elements are stored in continuous memory locations, it is easy to iterate on them. Containers handle the storage. We have learned that there are multiple ways to print a vector in C++, including by overloading the left shift operator (<<), using range-based for-loop, comma separator, indices, copy() function, for_each() function, and more.
Also read- 51 C++ Interview Questions For Freshers & Experienced (With Answers)
Frequently Asked Questions
Q. How to print vectors in C++ using an iterator?
Usually, we use constant iterators to get the start and end point of the vector, and another for loop iterates that iterates over each element in the defined range. An example code for the same is given below.
Code:
// C++ program to print vectors using iterators
#include <iostream>
#include <vector>
using namespace std;
template <typename ele_type>
void print( const vector<ele_type> &V){
for (auto itr = V.cbegin(); itr != V.cend(); itr++) {
cout << *itr << ' ';}
}
int main(){
vector<char> V = { '#', 'U', 'N', 'S', 'T', 'O', 'P'};
print(V);
return 0;
}
Output:
# U N S T O P
Explanation:
- The print() is a template function that takes vector (‘const vector<ele_type>& vector’) as an input argument and ele_type represents the type of elements in the vector.
- This function uses a for loop, which iterates over each vector element using the iterator itr.
- We deference the itr using the * operator and is printed followed by a space.
- The constant iterators cbegin() and cend() define the starting and end point of the range of the vector to be printed.
Q. How to print the first element of the vector in cpp?
The simplest way to print the first element of a vector in C++ is by using indices. Indexes refer to the position of the elements in a vector and are denoted by square brackets. Let's look at an implementation of the same for better understanding.
Code Example:
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<float> V = { 1.1, 2.2, 3.3, 4.4, 5.5 };
cout<<*V.begin()<<endl;
return 0;}
Output:
1.1
Explanation:
- The vector is first declared and initialized in the main function.
- V.begin() is a pointer that gives the address of the first element of the vector.
- The ‘*’ operator acts as a dereferencing operator that outputs the vector value present at the address pointed by V.begin() iterator.
Q. How is a vector created in C++?
When a vector is created in C++, the elements are inserted using the push_back() function. The elements are stored in adjacent memory locations, which allows easy traversal through the vector using iterators.
We use the following syntax to create a vector in C++:
vector <data_type> vector_name[vector_size];
Here,
- vector is the keyword for creating them.
- data_type refers to the type of elements in the vector.
- vector_name refers to the name given to the vector being created.
- vector_size is an optional field which refers to the number of elements in the vector.
Q. How to print a 2D string vector in C++?
We can use the nested for-loop to print a 2D vector of string type in C++. A nested loop is when we insert one for-loop inside another. Here the flow of control first passes through the outer loop and passes to the internal loop if the initial condition is met. The flow moves to the outer loop again when the inner loop terminates or finishes an iteration.
Let's take a look at the code snippet below to see how this is done:
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<vector<string>> str={{"Get","Mentors"},
{"At","Unstop"},
{"And","Grow"}};
for(int i=0; i<str.size(); i++){
for(int j=0; j<str[i].size(); j++){
cout<<str[i][j]<<" ";}
cout<<endl;}
return 0;
}
Output:
Get Mentors
At Unstop
And Grow
Explanation:
We begin by declaring and initializing a vector in the main function with string elements.
- The program then initiates a nested for loop, where the outer loop iterates over each row, and the inner loop is used to iterate over each column element of the current row indicated by variable ‘i’.
- We use str.size() to get the number of rows and str[0].size() to get the number of column elements in each row.
- The 2D string vector is printed using cout, with respective row elements in the same line and followed by space.
Q. Can you have a vector of multiple types in C++?
No. A vector of elements with different data types is not possible since the vector type is the property of a complete vector and is common to all of its elements. It is preferable to create a List in C++. It is a data structure that allows the storage of elements with different data types.
Q. How to print a char vector in C++?
There are multiple ways to print a vector in C++, for example, by overloading the left shift operator, using iterators, in-built functions, and indices, etc. Given below is an example of how to print a character array using indices.
Code:
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<char> V={'C','O','D','I','N','G'};
for(auto itr : V){
cout<<itr<<" ";}
return 0;
}
Output:
C O D I N G
Explanation:
- The initialized character vector is printed using a simple for loop, which iterates over each vector element using an iterator itr.
- The auto keyword helps the itr to automatically get the data type of vector elements.
Q. Can we have a string vector in C++?
C++ gives you the ability to create a string vector by including a string library in the program. This enables programmers to initialize a vector with string elements. Let’s look at an example to gain a better understanding of the same.
Code:
#include <iostream>
#include <vector>
#include <string>
#include <iterator>
using namespace std;
int main(){
vector<string> str={"This","is","a","string","vector."};
for(auto itr : str){
cout<<itr<<" ";}
return 0;
}
Output:
This is a string vector.
Explanation:
- We begin by including the string library to create a string vector. We also include other libraries important for creating vectors and printing the output on the console.
- Next, we initialize a string vector inside the main() function and initiate a for loop to iterate over its elements.
- The simple for loop iterates over each vector element that is a string using an iterator, it. And prints the element using cout.
- The auto keyword helps the itr to automatically get the data type of vector elements, and it is printed followed by a space.
This is how we can create a string vector. The example also showcases how to print a vector in C++ using a for-loop and space separator.
Quiz Time!!!
You might also be interested in reading the following:
- References In C++ | Declare, Types, Properties & More (+Examples)
- Typedef In C++ | Syntax, Application & How To Use It (With Examples)
- Comment In C++ | Types, Usage, C-Style Comments & More (+Examples)
- Storage Classes In C++ & Its Types Explained (With Examples)
- History Of C++ | Detailed Explanation (With Timeline Infographic)
An economics graduate with a passion for storytelling, I thrive on crafting content that blends creativity with technical insight. At Unstop, I create in-depth, SEO-driven content that simplifies complex tech topics and covers a wide array of subjects, all designed to inform, engage, and inspire our readers. My goal is to empower others to truly #BeUnstoppable through content that resonates. When I’m not writing, you’ll find me immersed in art, food, or lost in a good book—constantly drawing inspiration from the world around me.
Comments
Add commentLogin to continue reading
And access exclusive content, personalized recommendations, and career-boosting opportunities.

Subscribe
to our newsletter
Ritik Mishra 3 weeks ago
YASH SRIVASTAVA 3 weeks ago
Sanchit Dhale 3 weeks ago