Posts

6.Ternary operator and 7. Bitwise Operators

 6.Ternary operator:               It is a conditional operator(?:) which minimalize the conditional statements.it is easily inserted between code. Syntax: Symbol: ‘?:’ (condition)? statement: else statement; (x > y)? x: y; C++ program: which is greater one? #include <iostream> using namespace std; int main() {     int a, b;     cout<<"Enter the two numbers" <<endl;     cin>> a >> b;         // Using ternary operator     int g_val = (a > b) ? a : b;     cout << "The biggest of two numbers is: " << g_val;     return 0; } Output: Enter the two numbers 45 56 The biggest of two numbers is: 56 7. Bitwise Operators:               If you want to...

5. Unary Operators

     These operators need a single value to process the expression. The unary Operators are listed below. 1.    Increment operator (++) and Decrement operator(--): This operator deals with pre-increment(++Operand), post-increment(operand++), pre decrement(--Operand) and post decrement(Operand--).      Program: #include <iostream> using namespace std; int main() {     int x,y,z;     cout<<"Enter the number:";     cin>>x;     //pre increment     y = ++x;     //post incremnt     z = x++;     cout << "Pre increment value: " << y <<endl ;     cout << "Post increment value: " << x <<endl;     return 0; } Output: Enter the number:6 Pre increment value: 7 Post increment value: 8      Note ...

4.Relational Operators

               When you want to compare two values in terms of operands, this operator is used. List of relational   operators: ‘==’ – it checks that both operands are equal or not. ‘>’ – it checks the first operand is greater than the second operand. ‘<’ – it checks the first operand is less than or not. ‘>=’ – it checks for greater than or equal to ‘<=’ – it checks for less than or equal to ‘!=’ -it checks for not equal The c++ program example is given below. #include <iostream> using namespace std; int main() {     int x = 6, y = 4;     // checks for Equal operator     cout << "x == y is " << (x == y) << endl;     // checks for x is Greater than y     cout << "x > y is " << (x > y) << endl;     // checks for Greater than Equal     cout <...

3.Logical Operators

              Some symbols are used to find the logical values from the conditions. It returns the output as Boolean values either true or false. There are three logical operators in c++. Let us list out as follows… ‘&&’ – Logical AND Operator ‘||’ – Logical OR Operator ‘!’ – Logical NOT Operator Each and every logical operator is illustrated with examples…. ------------------------------------------------------------------------------------------------------------------------- Logical AND Operator(&&):               This operator returns true value when both of the operands are true. The truth table is given below. Operand1 Operand2 Output False False False False True False True False False True True True ...

2.Assignment Operators

               Assignment Operators are mainly used to assign the value. It uses the right to left assignment. The operators are listed below. ‘=’ – Assigns a value. ‘+=’ -Add the value and assign it. ‘-=’ – subtract the value and assign the value. ‘*=’ – multiply it and assign the value. ‘/=’ – divide and assign. Eg: x+=y means x=x+y; x-=y means x=x-y; x*=y means x =x*y; x/=y means x=x/y; A program displays the functionality of assignment operators #include <iostream> using namespace std;   int main() {     int x = 18, y = 3;       // Assignment Operator example.     cout << "x = " << x << endl;     cout << "y = " << y << endl;       //  Addition and Assignment Operator.     cout << "x += y is " << (x += y) << endl;       // Subtraction and ...

Operators in C++

              Operators are key components in any programming language. Operators can be classified into many types listed as follows…        Arithmetic Operators        Assignment Operators        Logical Operators         Relational Operators        Unary operators        Ternary Operators or Conditional Operators        Bitwise operators Each and every operators are detailed explained here. 1.Arithmetic Operators               As the name indicates, these are the operators for perform arithmetic expressions. It has ‘+’ for addition, ’-‘ for subtraction, ‘/’ for division, ‘*’ for multiplication and ‘%’ for mod operation. Each one is expressed in coding. C++ program to use Arithmetic operators:     ...

C++ Program to find ASCII value of Character and Vice Versa

       ASCII stands for American Standard Code for Information Interchange. It is an encoding standard mainly deals with electronic communication. Letters, digits and special characters are assigned with unique ASCII code. How it started?   In 1963, the first edition was developed from telegraph code.   Subsequent revisions in 1967 and 1986. ASCII character Set: It has 128 characters. It has unique seven-bit binary code. These characters include printable and control characters. For eg : null charcter   - it is represented by 0 00000000 For ‘A’, the ascii value is 65. It’s binary code is 01000001. It is world widely accepted character encoding. The upgraded version includes additional 128 characters. Let us create two c++ programs to convert ascii value into character and character into ascii value. C++ program to find ASCII Value of a character: #include <iostream> using namespace std; int main() {     ...