C++ 'compl' Keyword with Example

C++ | 'compl' keyword: Here, we are going to learn about the 'compl' keyword which is an alternative to Compliment operator.
Submitted by IncludeHelp, on May 16, 2020

"compl" is an inbuilt keyword that has been around since at least C++98. It is an alternative to ~ (Compliment) operator and it mostly uses for bit manipulations.

The compl keyword inverts all of the bits of the operand.

Syntax:

    compl operand

Here, operand is the operand.

Example:

    Input:
    bitset<4> value("1100");

    value = compl value;

    Output:
    value = 0011

C++ example to demonstrate the use of "compl" keyword

// C++ example to demonstrate the use of
// 'compl' keyword

#include <iostream>
#include <bitset>
using namespace std;

int main()
{
    //bitsets
    bitset<4> value("1011");

    // before operation
    cout << "value: " << value << endl;

    value = compl value;

    cout << "After operation (1)...\n";
    cout << "value: " << value << endl;

    value = compl value;

    cout << "After operation (2)...\n";
    cout << "value: " << value << endl;

    return 0;
}

Output:

value: 1011
After operation (1)...
value: 0100
After operation (2)...
value: 1011





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.