Can we use keywords in place of operators in C++ ?
Yes, certainly, we can. The ANSI C++ Standard has proposed keywords for several C++ operators . They originated in C in the header at the time when there were keyboards that couldn’t type the required symbols like &&, !, || etc.
In C++, they became alternate token just like regular tokens, except for spelling. So during parsing “and” is exactly the same as “&&”, it’s just a different way of spelling the same thing.
Consider the following expression:
x > y && m != 100, can be replaced by: x > y and m not_eq 100
Hi, we are in else if.
Similar to this, we can use keywords in place of all the operators mentioned in the table .
- Operator keyword enhances the readability of logical expressions.
- They are useful in situations when the keyboard doesnot support certain special characters such as &, ~ and ^, so we can use keywords in place of them.
Pitfall: Although, it is a very exciting feature of C++, but one needs to be a bit cautious while using it . Ordinarily, while, using these operators, we can write variables with or without leaving a space before or after these operators, but, when these operators are replaced by keywords, it becomes mandatory to leave a space after and before these keywords, as demonstrated below :
- Object-Oriented Programming with C++ by E. Balagurusamy
This article is contributed by Mrigendra Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- Order of operands for logical operators
- Check if a number can be written as sum of three consecutive integers
- Anything written in sizeof() is never executed in C
- Sum of digits written in different bases from 2 to n-1
- What are the operators that can be and cannot be overloaded in C++?
- Increment (Decrement) operators require L-value Expression
- Advanced C++ | Conversion Operators
- const_cast in C++ | Type Casting operators
- Bitwise Operators in C/C++
- Increment and Decrement Operators in Python
- How to sum two integers without using arithmetic operators in C/C++?
- Execution of printf with ++ operators
- Basic Operators in Java
- Conditionally assign a value without using conditional and arithmetic operators
- new and delete operators in C++ for dynamic memory
- Overloading stream insertion (<>) operators in C++
- Operators in C / C++
- Case conversion (Lower to Upper and Vice Versa) of a string using BitWise operators in C/C++
- Comparing String objects using Relational Operators in C++
- Largest of two distinct numbers without using any conditional statements or operators