For those who are preparing for C++ interviews in product-based companies, there is one question that is commonly asked:
Which of the following operators cannot be overloaded in C++?
This may seem like a very basic question; however, it is asked to test your knowledge about operator overloading, Object Oriented Programming (OOPs) and the C++ language itself.
Regardless of the firm you are preparing for, which includes companies like Amazon, Microsoft, Google, Adobe, Atlassian, and Walmart Global Technologies, this is one of the most common C++ interview questions.
In this blog, you will learn:
- What is Operator Overloading?
- The operators which cannot be overloaded in C++
- Reasons why these operators are restricted
- Operators which can be overloaded
- Examples
- Interview Questions
- Common Mistakes
What is Operator Overloading in C++?
Operator overloading lets you define a new meaning for an operator when working with user-defined objects.
The + operator adds two numbers:
int a = 5;
int b = 10;
cout << a + b;But you can use it for adding two objects together.
Complex c1, c2;
Complex c3 = c1 + c2;It doesn’t add numbers but uses a specific function programmed by the programmer. The code becomes more readable and neat because of that. Operator overloading is a widely used example of compile-time polymorphism.
Which Operators Cannot Be Overloaded in C++?
Only a few operators are restricted by the C++ language.
Operators that cannot be overloaded are:
| Operator | Purpose |
|---|---|
| :: | Scope Resolution Operator |
| . | Member Access Operator |
| .* | Pointer-to-Member Operator |
| ?: | Conditional (Ternary) Operator |
| sizeof | Returns object size |
These operators are always executed as per their definition and cannot be overloaded.
Easy Way to Remember
Try this shortcut for interviews:
Scope, Dot, Pointer Dot, Ternary, Sizeof
Or you can remember in short:
:: . .* ?: sizeofMost interviewers have used this shortcut for quick revision.
Why Do These Operators Not Support Overloading?
The C++ compiler relies on these operators to perform basic tasks.
Any modification in their working will make the programming language very unpredictable.
Let us learn about them.
1.Scope Resolution Operator (::)
Used to access:
→ Static member variables
→ Namespaces
→ Global variables
→ Member functions of classes
Examples:
std::coutIf we had the option to overload this operator, then it will become very difficult for the compiler to identify the scope of variables and functions.
2. Member Access Operator (.)
Used for accessing members of objects.
student.nameThe compiler uses this operator for finding variables and functions defined within the object.
Any change in the operator will disable access to object members entirely.
3. Pointer to Member Operator (.*)
Used for operations involving pointers to class members.
Usage:
object.*memberPointerThough not commonly used by developers, it is a crucial operator and thus cannot be overloaded.
4. Ternary Conditional Operator (?:)
Usage:
age >= 18 ? "Adult" : "Minor";The ternary conditional operator regulates conditional evaluations.
Modification of this operator will produce inconsistent code.
5. Sizeof Operator
Usage:
sizeof(int)The size of an object is calculated by the compiler at compile time.
Changing its behavior would affect memory management and compiler optimizations.

Which Operators Can Be Overloaded?
Fortunately, most C++ operators can be overloaded.
Some commonly overloaded operators include:
| Operator | Uses |
|---|---|
| + | Addition |
| - | Subtraction |
| * | Multiplication |
| / | Division |
| % | Modulus |
| == | Equality |
| != | Not Equal |
| < | Less Than |
| > | Greater Than |
| <= | Less Than or Equal |
| >= | Greater Than or Equal |
| >= | Greater Than or Equal |
| [] | Array Index |
| [] | Array Index |
| () | Function Call |
| << | Stream Insertion |
| >> | Stream Extraction |
| ++ | Increment |
| -- | Decrement |
| -> | Arrow Operator |
| new | Memory Allocation |
| delete | Memory Deallocation |
Example of Operator Overloading
#include <iostream>
using namespace std;
class Complex {
public:
int real, imag;
Complex(int r, int i) {
real = r;
imag = i;
}
Complex operator + (Complex const &obj) {
return Complex(real + obj.real,
imag + obj.imag);
}
};
int main() {
Complex c1(2,3);
Complex c2(4,5);
Complex c3 = c1 + c2;
cout << c3.real << " + " << c3.imag << "i";
}Output:
6 + 8iThe '+' operator no longer performs simple integer addition but rather Complex object addition.
Rules for Operator Overloading in C++
Remember these important rules:
- At least one of the operands must be of a user-defined type.
- We cannot define new operators.
- Operators' precedence cannot be changed.
- Associativity of operators cannot be altered.
- Number of operands will not change.
- Some operators should always be overloaded as member functions.
Common interview questions
1. Which of the following operators cannot be overloaded in C++?
Answer:
::
.
.*
? :
sizeof
2. Why is the operator sizeof non-overloadable?
It is used by the compiler to find out the size of an object at the time of compilation.
3. Can we overload the assignment operator (=)?
Yes. Assignment operator is over loadable.
4. Can we overload the 'new' and 'delete' operators?
Yes. They are usually overloaded for memory manipulation.
5. Can we overload any operators for primitive data types?
No. Because at least one of the operands should be of a user-defined class or structure.
Common Mistakes Learners Make
These are some typical errors that many learner commit:
→ Believing that all operators can be overloaded
→ Believing that the sizeof operator can be customized
→ Attempting to overload the dot operator (.)
→ Failing to remember that the precedence of an operator cannot be altered
Avoiding these mistakes would surely save your valuable time in coding interview rounds.
Importance of This Question in Product-Based Companies
Questions on operator overloading are commonly included in product-based companies because:
- Knowledge of Object-Oriented Programming (OOPs) is being tested
- Knowledge about the internal working of C++ language is being tested
- Knowledge about compile-time polymorphism is being tested
- Knowledge about memory management is being tested
- Knowledge about compiler functioning is being tested
If you're targeting software engineering roles, mastering topics like C++, Data Structures & Algorithms, Operating Systems, DBMS, Computer Networks, and System Design is essential. Interviewers expect candidates to understand not only how features work but also why the language is designed that way.
Upskill for Product-Based Companies with Bosscoder Academy
Memorizing questions is not the best way to clear interviews at top software engineering companies.
Working professionals prepare for Software Engineering interviews at Bosscoder Academy with the following topics covered in their Software Engineering Program:
→ Data Structures & Algorithms
→ C++ and Java Interview Preparation
→ Operating Systems
→ DBMS
→ Computer Networks
→ System Design
→ Low-Level Design
→ Mock Interviews with expert mentors
→ Interview preparation for top product-based companies
Are you looking to change careers or land a high paying software engineering job? Building a solid Computer Science foundation along with consistent coding practice will definitely help you in cracking interviews.
Conclusion
It was easy to identify the answer for the interview question "Which of the following operators cannot be overloaded in C++"
There are five operators which cannot be overloaded, which are:
::
.
.*
?:
sizeof
Remember the above operators as it will surely come handy in coding interviews and tests.
Understanding the reason why the above operators cannot be overloaded will also benefit you in your interview preparation.
Frequently Asked Questions (FAQs)
Q1. Which operator cannot be overloaded in C++?
The operators that can't be overloaded in C++ are ::, ., .*, ?:, and sizeof, because these are basic operators used by the C++ programming language.
Q2. Why are some operators not overloaded in C++?
This is because these operators manage the functionality of some important features of the C++ language, which is why they cannot be overloaded in any way.
Q3. Which operators are overloaded in C++?
The operators that are overloaded in C++ include +, -, *, /, ==, !=, [], (), <<, >>, ++, --, new, and delete.
Q4. Is operator overloading important for a coding interview?
It is highly relevant. The operator overloading is a widely asked topic in C++ coding interviews, especially in product-based companies.
It is highly relevant. The operator overloading is a widely asked topic in C++ coding interviews, especially in product-based companies.









