Logical Operators Examples in C++


Description:

Logical Operators are used to combine two or more conditions/constraints or to complement the evaluation of the original condition in consideration. The result of the operation of a logical operator is a boolean value either true or false. For example, the logical AND represented as ‘&&’ operator in C or C++ returns true when both the conditions under consideration are satisfied. Otherwise it returns false. Therfore, a && b returns true when both a and b are true (i.e. non-zero).

Example Program:

Here is the simple program logical operators examples in C++.

Source Code

#include <iostream>
using namespace std;
int main()
{
    int a=10,b=40,c;
    if(a && b)
    {
        cout<<"1st - Condition is true"<<endl ;
    }

    if(a||b)
    {
        cout<<"\n2nd - Condition is true"<<endl ;
    }
    a=0;
    b=10;
    if(a&&b)
    {
        cout <<"\n3rd - Condition is true"<<endl ;
    }
    else
    {
        cout <<"\n3rd - Condition is not true"<< endl ;
    }
    if(!(a&&b))
    {
        cout <<"\n5th - Condition is true"<< endl ;
    }
    return 0;
}
To download raw file Click Here

Output

1st - Condition is true

2nd - Condition is true

3rd - Condition is not true

5th - Condition is true

Basic Programs


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples



Learn All in Tamil © Designed & Developed By Tutor Joes