An operator is a symbol that operates on a value to perform specific mathematical or logical computations. They form the foundation of any programming language. In C++, we have built-in operators to provide the required functionality.
An operator operates the operands. For example,
int c = a + b;
Here, ‘+’ is the addition operator. ‘a’ and ‘b’ are the operands that are being ‘added’.
Operators in C++ can be classified into 6 types:
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Ternary or Conditional Operators

1) Arithmetic Operators
These operators are used to perform arithmetic or mathematical operations on the operands. For example, ‘+’ is used for addition, ‘-‘ is used for subtraction ‘*’ is used for multiplication, etc.
Arithmetic Operators can be classified into 2 Types:
A) Unary Operators: These operators operate or work with a single operand. For example: Increment(++) and Decrement(–) Operators.
| Name | Symbol | Description | Example |
|---|
| Increment Operator | ++ | Increases the integer value of the variable by one | int a = 5;
a++; // returns 6
|
| Decrement Operator | — | Decreases the integer value of the variable by one | int a = 5;
a–; // returns 4
|
Example:
the description
Outputa++ is 10
++a is 12
b-- is 15
--b is 13
Time Complexity: O(1)
Auxiliary Space : O(1)
Note: ++a and a++, both are increment operators, however, both are slightly different.
In ++a, the value of the variable is incremented first and then It is used in the program. In a++, the value of the variable is assigned first and then It is incremented. Similarly happens for the decrement operator.
B) Binary Operators: These operators operate or work with two operands. For example: Addition(+), Subtraction(-), etc.
| Name | Symbol | Description | Example |
|---|
| Addition | + | Adds two operands | int a = 3, b = 6;
int c = a+b; // c = 9
|
| Subtraction | – | Subtracts second operand from the first | int a = 9, b = 6;
int c = a-b; // c = 3
|
| Multiplication | * | Multiplies two operands | int a = 3, b = 6;
int c = a*b; // c = 18
|
| Division | / | Divides first operand by the second operand | int a = 12, b = 6;
int c = a/b; // c = 2
|
| Modulo Operation | % | Returns the remainder an integer division | int a = 8, b = 6;
int c = a%b; // c = 2
|
Note: The Modulo operator(%) operator should only be used with integers.
Example:
C++
// CPP Program to demonstrate the Binary Operators
#include <iostream>
using namespace std;
int main()
{
int a = 8, b = 3;
// Addition operator
cout << "a + b = " << (a + b) << endl;
// Subtraction operator
cout << "a - b = " << (a - b) << endl;
// Multiplication operator
cout << "a * b = " << (a * b) << endl;
// Division operator
cout << "a / b = " << (a / b) << endl;
// Modulo operator
cout << "a % b = " << (a % b) << endl;
return 0;
}
Outputa + b = 11
a - b = 5
a * b = 24
a / b = 2
a % b = 2
Time Complexity: O(1)
Auxiliary Space : O(1)
2) Relational Operators
These operators are used for the comparison of the values of two operands. For example, ‘>’ checks if one operand is greater than the other operand or not, etc. The result returns a Boolean value, i.e., true or false.
| Name | Symbol | Description | Example |
|---|
| Is Equal To | == | Checks if both operands are equal | int a = 3, b = 6;
a==b;
// returns false
|
| Greater Than | > | Checks if first operand is greater than the second operand | int a = 3, b = 6;
a>b;
// returns false
|
| Greater Than or Equal To | >= | Checks if first operand is greater than or equal to the second operand | int a = 3, b = 6;
a>=b;
// returns false
|
| Less Than | < | Checks if first operand is lesser than the second operand | int a = 3, b = 6;
a<b;
// returns true
|
| Less Than or Equal To | <= | Checks if first operand is lesser than or equal to the second operand | int a = 3, b = 6;
a<=b;
// returns true
|
| Not Equal To | != | Checks if both operands are not equal | int a = 3, b = 6;
a!=b;
// returns true
|
Example:
C++
// CPP Program to demonstrate the Relational Operators
#include <iostream>
using namespace std;
int main()
{
int a = 6, b = 4;
// Equal to operator
cout << "a == b is " << (a == b) << endl;
// Greater than operator
cout << "a > b is " << (a > b) << endl;
// Greater than or Equal to operator
cout << "a >= b is " << (a >= b) << endl;
// Lesser than operator
cout << "a < b is " << (a < b) << endl;
// Lesser than or Equal to operator
cout << "a <= b is " << (a <= b) << endl;
// true
cout << "a != b is " << (a != b) << endl;
return 0;
}
Outputa == b is 0
a > b is 1
a >= b is 1
a < b is 0
a <= b is 0
a != b is 1
Time Complexity: O(1)
Auxiliary Space : O(1)
Here, 0 denotes false and 1 denotes true. To read more about this, please refer to the article – Relational Operators.
3) Logical Operators
These operators are used to combine two or more conditions or constraints or to complement the evaluation of the original condition in consideration. The result returns a Boolean value, i.e., true or false.
| Name | Symbol | Description | Example |
|---|
| Logical AND | && | Returns true only if all the operands are true or non-zero | int a = 3, b = 6;
a&&b;
// returns true
|
| Logical OR | || | Returns true if either of the operands is true or non-zero | int a = 3, b = 6;
a||b;
// returns true
|
| Logical NOT | ! | Returns true if the operand is false or zero | int a = 3;
!a;
// returns false
|
Example:
C++
// CPP Program to demonstrate the Logical Operators
#include <iostream>
using namespace std;
int main()
{
int a = 6, b = 4;
// Logical AND operator
cout << "a && b is " << (a && b) << endl;
// Logical OR operator
cout << "a || b is " << (a || b) << endl;
// Logical NOT operator
cout << "!b is " << (!b) << endl;
return 0;
}
Outputa && b is 1
a ! b is 1
!b is 0
Time Complexity: O(1)
Auxiliary Space : O(1)
Here, 0 denotes false and 1 denotes true. To read more about this, please refer to the article – Logical Operators.
4) Bitwise Operators
These operators are used to perform bit-level operations on the operands. The operators are first converted to bit-level and then the calculation is performed on the operands. Mathematical operations such as addition, subtraction, multiplication, etc. can be performed at the bit level for faster processing.
| Name | Symbol | Description | Example |
|---|
| Binary AND | & | Copies a bit to the evaluated result if it exists in both operands | int a = 2, b = 3;
(a & b); //returns 2
|
| Binary OR | | | Copies a bit to the evaluated result if it exists in any of the operand | int a = 2, b = 3;
(a | b); //returns 3
|
| Binary XOR | ^ | Copies the bit to the evaluated result if it is present in either of the operands but not both | int a = 2, b = 3;
(a ^ b); //returns 1
|
| Left Shift | << | Shifts the value to left by the number of bits specified by the right operand. | int a = 2, b = 3;
(a << 1); //returns 4
|
| Right Shift | >> | Shifts the value to right by the number of bits specified by the right operand. | int a = 2, b = 3;
(a >> 1); //returns 1
|
| One’s Complement | ~ | Changes binary digits 1 to 0 and 0 to 1 | int b = 3;
(~b); //returns -4
|
Note: Only char and int data types can be used with Bitwise Operators.
Example:
C++
// CPP Program to demonstrate the Bitwise Operators
#include <iostream>
using namespace std;
int main()
{
int a = 6, b = 4;
// Binary AND operator
cout << "a & b is " << (a & b) << endl;
// Binary OR operator
cout << "a | b is " << (a | b) << endl;
// Binary XOR operator
cout << "a ^ b is " << (a ^ b) << endl;
// Left Shift operator
cout << "a<<1 is " << (a << 1) << endl;
// Right Shift operator
cout << "a>>1 is " << (a >> 1) << endl;
// One’s Complement operator
cout << "~(a) is " << ~(a) << endl;
return 0;
}
Outputa & b is 4
a | b is 6
a ^ b is 2
a<<1 is 12
a>>1 is 3
~(a) is -7
Time Complexity: O(1)
Auxiliary Space : O(1)
To read more about this, please refer to the article – Bitwise Operators.
5) Assignment Operators
These operators are used to assign value to a variable. The left side operand of the assignment operator is a variable and the right side operand of the assignment operator is a value. The value on the right side must be of the same data type as the variable on the left side otherwise the compiler will raise an error.
Namemultiply
| Symbol
| Description
| Example
|
|---|
| Assignment Operator | =
| Assigns the value on the right to the variable on the left | int a = 2;
// a = 2
|
| Add and Assignment Operator | +=
| First adds the current value of the variable on left to the value on the right and then assigns the result to the variable on the left | int a = 2, b = 4;
a+=b; // a = 6
|
| Subtract and Assignment Operator | -=
| First subtracts the value on the right from the current value of the variable on left and then assign the result to the variable on the left | int a = 2, b = 4;
a-=b; // a = -2
|
| Multiply and Assignment Operator | *=
| First multiplies the current value of the variable on left to the value on the right and then assign the result to the variable on the left | int a = 2, b = 4;
a*=b; // a = 8
|
| Divide and Assignment Operator | /=
| First divides the current value of the variable on left by the value on the right and then assign the result to the variable on the left | int a = 4, b = 2;
a /=b; // a = 2
|
Example:
C++
// CPP Program to demonstrate the Assignment Operators
#include <iostream>
using namespace std;
int main()
{
int a = 6, b = 4;
// Assignment Operator
cout << "a = " << a << endl;
// Add and Assignment Operator
cout << "a += b is " << (a += b) << endl;
// Subtract and Assignment Operator
cout << "a -= b is " << (a -= b) << endl;
// Multiply and Assignment Operator
cout << "a *= b is " << (a *= b) << endl;
// Divide and Assignment Operator
cout << "a /= b is " << (a /= b) << endl;
return 0;
}
Outputa = 6
a += b is 10
a -= b is 6
a *= b is 24
a /= b is 6
Time Complexity: O(1)
Auxiliary Space : O(1)
6) Ternary or Conditional Operators(?:)
This operator returns the value based on the condition.
Expression1? Expression2: Expression3
The ternary operator ? determines the answer on the basis of the evaluation of Expression1. If it is true, then Expression2 gets evaluated and is used as the answer for the expression. If Expression1 is false, then Expression3 gets evaluated and is used as the answer for the expression.
This operator takes three operands, therefore it is known as a Ternary Operator.
Example:
C++
// CPP Program to demonstrate the Conditional Operators
#include <iostream>
using namespace std;
int main()
{
int a = 3, b = 4;
// Conditional Operator
int result = (a < b) ? b : a;
cout << "The greatest number is " << result << endl;
return 0;
}
OutputThe greatest number is 4
Time Complexity: O(1)
Auxiliary Space : O(1)
7) There are some other common operators available in C++ besides the operators discussed above. Following is a list of these operators discussed in detail:
A) sizeof Operator: This unary operator is used to compute the size of its operand or variable.
sizeof(char); // returns 1
B) Comma Operator(,): This binary operator (represented by the token) is used to evaluate its first operand and discards the result, it then evaluates the second operand and returns this value (and type). It is used to combine various expressions together.
int a = 6;
int b = (a+1, a-2, a+5); // b = 11
C) -> Operator: This operator is used to access the variables of classes or structures.
cout<<emp->first_name;
D) Cast Operator: This unary operator is used to convert one data type into another.
float a = 11.567;
int c = (int) a; // returns 11
E) Dot Operator(.): This operator is used to access members of structure variables or class objects in C++.
cout<<emp.first_name;
F) & Operator: This is a pointer operator and is used to represent the memory address of an operand.
G) * Operator: This is an Indirection Operator
C++
// CPP Program to demonstrate the & and * Operators
#include <iostream>
using namespace std;
int main()
{
int a = 6;
int* b;
int c;
// & Operator
b = &a;
// * Operator
c = *b;
cout << " a = " << a << endl;
cout << " b = " << b << endl;
cout << " c = " << c << endl;
return 0;
}
Output a = 6
b = 0x7ffe8e8681bc
c = 6
H) << Operator: It is called the insertion operator. It is used with cout to print the output.
I) >> Operator: It is called the extraction operator. It is used with cin to get the input.
int a;
cin>>a;
cout<<a;
Time Complexity: O(1)
Auxiliary Space : O(1)
Operator Precedence Chart
| Precedence | Operator | Description | Associativity |
|---|
| 1. | () | Parentheses (function call) | left-to-right |
| [] | Brackets (array subscript) | |
| . | Member selection via object name | |
| -> | Member selection via a pointer | |
| ++/– | Postfix increment/decrement | |
| 2. | ++/– | Prefix increment/decrement | right-to-left |
| +/- | Unary plus/minus | |
| !~ | Logical negation/bitwise complement | |
| (type) | Cast (convert value to temporary value of type) | |
| * | Dereference | |
| & | Address (of operand) | |
| sizeof | Determine size in bytes on this implementation | |
| 3. | *,/,% | Multiplication/division/modulus | left-to-right |
| 4. | +/- | Addition/subtraction | left-to-right |
| 5. | << , >> | Bitwise shift left, Bitwise shift right | left-to-right |
| 6. | < , <= | Relational less than/less than or equal to | left-to-right |
| > , >= | Relational greater than/greater than or equal to | left-to-right |
| 7. | == , != | Relational is equal to/is not equal to | left-to-right |
| 8. | & | Bitwise AND | left-to-right |
| 9. | ^ | Bitwise exclusive OR | left-to-right |
| 10. | | | Bitwise inclusive OR | left-to-right |
| 11. | && | Logical AND | left-to-right |
| 12. | || | Logical OR | left-to-right |
| 13. | ?: | Ternary conditional | right-to-left |
| 14. | = | Assignment | right-to-left |
| += , -= | Addition/subtraction assignment | |
| *= , /= | Multiplication/division assignment | |
| %= , &= | Modulus/bitwise AND assignment | |
| ^= , |= | Bitwise exclusive/inclusive OR assignment | |
| <>= | Bitwise shift left/right assignment | |
| 15. | , | expression separator | left-to-right |
Similar Reads
C++ Tutorial | Learn C++ Programming
C++ is a middle-level programming language that was developed as an extension of the C programming language. In the early 1980s, Bell Labs was an enhancement of the C language to provide support for OOPs (Object Oriented Programming Systems) and additional features. When you look for the successor o
7 min read
Setting up C++ Development Environment
C++ is a general-purpose programming language and is widely used nowadays for competitive programming. It has imperative, object-oriented, and generic programming features. C++ runs on lots of platforms like Windows, Linux, Unix, Mac, etc. Before we start programming with C++. We will need an enviro
8 min read
Writing First C++ Program - Hello World Example
The "Hello World" program is the first step towards learning any programming language and is also one of the most straightforward programs you will learn. It is the basic program that is used to demonstrate how the coding process works. All you have to do is display the message "Hello World" on the
3 min read
C++ Variables
In C++, variable is a name given to a memory location. It is the basic unit of storage in a program. The value stored in a variable can be accessed or changed during program execution. In this article, we will learn about the variables in C++ and how to use them in our programs. Let's take a look at
4 min read
C++ Data Types
Data types specify the type of data that a variable can store. Whenever a variable is defined in C++, the compiler allocates some memory for that variable based on the data type with which it is declared as every data type requires a different amount of memory. C++ supports a wide variety of data ty
6 min read
Operators in C++
An operator is a symbol that operates on a value to perform specific mathematical or logical computations. They form the foundation of any programming language. In C++, we have built-in operators to provide the required functionality. An operator operates the operands. For example, int c = a + b;He
13 min read
Basic Input / Output in C++
C++ comes with libraries that provide us with many ways for performing input and output. In C++ input and output are performed in the form of a sequence of bytes or more commonly known as streams. Input Stream: If the direction of flow of bytes is from the device(for example, Keyboard) to the main m
5 min read
Decision Making in C++
Decision Making in C (if , if..else, Nested if, if-else-if )
The conditional statements (also known as decision control structures) such as if, if else, switch, etc. are used for decision-making purposes in C programs. They are also known as Decision-Making Statements and are used to evaluate one or more conditions and make the decision whether to execute a s
11 min read
C++ if Statement
The C++ if statement is the most simple decision-making statement. It is used to decide whether a certain statement or block of statements will be executed or not executed based on a certain condition. Let's take a look at an example: [GFGTABS] C++ #include <iostream> using namespace std; int
3 min read
C++ if else Statement
The if statement alone tells us that if a condition is true it will execute a block of statements and if the condition is false, it won’t. But what if we want to do something else if the condition is false. Here comes the C++ if else statement. We can use the else statement with if statement to exec
4 min read
C++ if else if Ladder
In C++, the if-else-if ladder helps the user decide from among multiple options. The C++ if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the C++ else-if ladder is bypassed. I
3 min read
C++ Nested if-else Statement
Nested if-else statements are those statements in which there is an if statement inside another if else. We use nested if-else statements when we want to implement multilayer conditions (condition inside the condition inside the condition and so on). C++ allows any number of nesting levels. Let's ta
3 min read
Switch Statement in C++
In C++, the switch statement is a flow control statement that is used to execute the different blocks of statements based on the value of the given expression. It is an alternative to the long if-else-if ladder which provides an easy way to execute different parts of code based on the value of the e
7 min read
Jump statements in C++
Jump statements are used to manipulate the flow of the program if some conditions are met. It is used to terminate or continue the loop inside a program or to stop the execution of a function. In C++, there is four jump statement: Table of Content continue Statementbreak Statementreturn Statementgot
4 min read
C++ Loops
C++ Loops
In Programming, sometimes there is a need to perform some operation more than once or (say) n number of times. Loops come into use when we need to repeatedly execute a block of statements. For example: Suppose we want to print "Hello World" 10 times. This can be done in two ways as shown below: Ma
13 min read
for Loop in C++
In C++, for loop is an entry-controlled loop that is used to execute a block of code repeatedly for the given number of times. It is generally preferred over while and do-while loops in case the number of iterations is known beforehand. Let's take a look at an example: [GFGTABS] C++ #include <bit
6 min read
C++ While Loop
In C++, the while loop is an entry-controlled loop that repeatedly executes a block of code as long as the given condition remains true. Unlike the for loop, while loop is used in situations where we do not know the exact number of iterations of the loop beforehand as the loop execution is terminate
3 min read
C++ do while Loop
In C++, the do-while loop is an exit-controlled loop that repeatedly executes a block of code at least once and continues executing as long as a given condition remains true. Unlike the while loop, the do-while loop guarantees that the loop body will execute at least once, regardless of whether the
4 min read
Range-Based for Loop in C++
In C++, the range-based for loop introduced in C++ 11 is a version of for loop that is able to iterate over a range. This range can be anything that is iteratable, such as arrays, strings and STL containers. It provides a more readable and concise syntax compared to traditional for loops. Let's take
4 min read
Functions in C++
A function is a set of statements that takes input, does some specific computation, and produces output. The idea is to put some commonly or repeatedly done tasks together to make a function so that instead of writing the same code again and again for different inputs, we can call this function.In s
15+ min read
Pointers and References in C++
In C++ pointers and references both are mechanisms used to deal with memory, memory address, and data in a program. Pointers are used to store the memory address of another variable whereas references are used to create an alias for an already existing variable. Pointers in C++ Pointers in C++ are a
5 min read
C++ Arrays
In C++, an array is a data structure that is used to store multiple values of similar data types in a contiguous memory location. For example, if we have to store the marks of 4 or 5 students then we can easily store them by creating 5 different variables but what if we want to store marks of 100 st
14 min read
Strings in C++
C++ strings are sequences of characters stored in a char array. Strings are used to store words and text. They are also used to store data, such as numbers and other types of information. Strings in C++ can be defined either using the std::string class or the C-style character arrays. 1. C Style Str
11 min read
Structures, Unions and Enumerations in C++
In this article, we will discuss structures, unions, and enumerations and their differences. The structure is a user-defined data type that is available in C++.Structures are used to combine different types of data types, just like an array is used to combine the same type of data types.A structure
5 min read
new and delete Operators in C++ For Dynamic Memory
Dynamic memory allocation in C/C++ refers to performing memory allocation manually by a programmer. Dynamically allocated memory is allocated on Heap, and non-static and local variables get memory allocated on Stack (Refer to Memory Layout C Programs for details). What are applications? One use of d
6 min read
C++ Object Oriented Programming (OOPs)
Object Oriented Programming in C++
Object-oriented programming - As the name suggests uses objects in programming. Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism, etc. in programming. The main aim of OOP is to bind together the data and the functions that operate on them so th
10 min read
C++ Classes and Objects
In C++, classes and objects are the basic building block that leads to Object-Oriented programming in C++. In this article, we will learn about C++ classes, objects, look at how they work and how to implement them in our C++ program. What is a Class in C++?A class is a user-defined data type, which
10 min read
Encapsulation in C++
Encapsulation in C++ is defined as the wrapping up of data and information in a single unit. In Object Oriented Programming, Encapsulation is defined as binding together the data and the functions that manipulate them. Consider a real-life example of encapsulation, in a company, there are different
5 min read
Abstraction in C++
Data abstraction is one of the most essential and important features of object-oriented programming in C++. Abstraction means displaying only essential information and ignoring the details. Data abstraction refers to providing only essential information about the data to the outside world, ignoring
4 min read
C++ Polymorphism
The word "polymorphism" means having many forms. In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form. A real-life example of polymorphism is a person who at the same time can have different characteristics. A man at the same time is a father,
7 min read
Inheritance in C++
The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is one of the most important features of Object Oriented Programming in C++. In this article, we will learn about inheritance in C++, its modes and types along with the informatio
15+ min read
Exception Handling in C++
In C++, exceptions are runtime anomalies or abnormal conditions that a program encounters during its execution. The process of handling these exceptions is called exception handling. Using the exception handling mechanism, the control from one part of the program where the exception occurred can be
11 min read
File Handling through C++ Classes
File handling is used to store data permanently in a computer. Using file handling we can store our data in secondary memory (Hard disk).How to achieve the File HandlingFor achieving file handling we need to follow the following steps:- STEP 1-Naming a file STEP 2-Opening a file STEP 3-Writing data
8 min read
Templates in C++ with Examples
A template is a simple yet very powerful tool in C++. The simple idea is to pass the data type as a parameter so that we don't need to write the same code for different data types. For example, a software company may need to sort() for different data types. Rather than writing and maintaining multip
10 min read
The C++ Standard Template Library (STL)
C++ Standard Template Library (STL)
The C++ Standard Template Library (STL) is a set of template classes and functions that provides the implementation of common data structures and algorithms such as lists, stacks, arrays, sorting, searching, etc. It also provides the iterators and functors which makes it easier to work with algorith
9 min read
Vector in C++ STL
In C++, vector is a dynamic array with the ability to resize itself automatically when an element is inserted or deleted. It is the part Standard Template Library (STL) and provide various useful functions for data manipulation. Let's take a look a simple example to demonstrate the use of vector con
9 min read
List in C++ Standard Template Library (STL)
Lists are sequence containers that allow non-contiguous memory allocation. As compared to the vector, the list has slow traversal, but once a position has been found, insertion and deletion are quick (constant time). Normally, when we say a List, we talk about a doubly linked list. For implementing
6 min read
Queue in C++ Standard Template Library (STL)
Queues are a type of container adaptors that operate in a first in first out (FIFO) type of arrangement. Elements are inserted at the back (end) and are deleted from the front. Queues use an encapsulated object of deque or list (sequential container class) as its underlying container, providing a sp
4 min read
Set in C++ Standard Template Library (STL)
Sets are a type of associative container in which each element has to be unique because the value of the element identifies it. The values are stored in a specific sorted order i.e. either ascending or descending. The std::set class is the part of C++ Standard Template Library (STL) and it is define
7 min read
Map in C++ Standard Template Library (STL)
Maps are associative containers that store elements in a mapped fashion. Each element has a key value and a mapped value. No two mapped values can have the same key values. std::map is the class template for map containers and it is defined inside the <map> header file. Basic std::map Member F
9 min read
Introduction to Iterators in C++
An iterator is an object (like a pointer) that points to an element inside the container. We can use iterators to move through the contents of the container. They can be visualized as something similar to a pointer pointing to some location and we can access the content at that particular location u
6 min read
Algorithm Library | C++ Magicians STL Algorithm
For all those who aspire to excel in competitive programming, only having a knowledge about containers of STL is of less use till one is not aware what all STL has to offer. STL has an ocean of algorithms, for all < algorithm > library functions : Refer here.Some of the most used algorithms on
7 min read
sort() in C++ STL
In C++, sort() is a built-in function used to sort the given range in desired order. It provides a simple and efficient way to sort the data in C++ but it only works on data structures that provide random access to its elements such as vectors and arrays. Let's take a look at an example: [GFGTABS] C
4 min read
for_each loop in C++
Apart from the generic looping techniques, such as "for, while and do-while", C++ in its language also allows us to use another functionality which solves the same purpose termed "for-each" loops. This loop accepts a function which executes over each of the container elements. This loop is defined i
5 min read
Functors in C++
Please note that the title is Functors (Not Functions)!! Consider a function that takes only one argument. However, while calling this function we have a lot more information that we would like to pass to this function, but we cannot as it accepts only one parameter. What can be done? One obvious an
3 min read
C Preprocessors
Preprocessors are programs that process the source code before compilation. Several steps are involved between writing a program and executing a program in C. Let us have a look at these steps before we actually start learning about Preprocessors. You can see the intermediate steps in the above diag
10 min read