TOPIC: Constants, Manipulators and Operator Precedence in C++
Constants
C++ Program - Constants
Code written in Visual Studio Code
Manipulators
C++ Program - Manipulators
Code written in Visual Studio Code
In the above output, the value is formatted to the right when we use setw()
Operator Precedence in C++
Operators | Precedence |
---|---|
++ (post increment), -- (post decrement) | Highest |
++ (pre-increment), --
(pre-decrement), sizeof, ! (not), - (unary minus), + (unary plus) |
↓ |
* (multiply), / (divide), % (modulus) | ↓ |
+ (add), - (subtract) | ↓ |
< (less than), <=(less than or equal), > (greater than), >= (greater than or equal) |
↓ |
== (equal), != (not equal) | ↓ |
&& (logical AND) | ↓ |
|| (logical OR) | ↓ |
?: (conditional expression) | ↓ |
= (simple assignment operator) | ↓ |
comma operator | lowest |
In the above table, we can see that the operators are given from Highest to lowest precedence of operators.
C++ Program - Precedence of Operators
Code written in Visual Studio Code
You can write more code examples for checking precedence for yourselves. You can also check more about C++ operator precedence on website cppreference.com
More blog posts coming soon!
Coding is the art of turning imagination into innovation.
- Unknown