
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
What are the differences between bitwise and logical AND operators in C/C++
As we know the bit-wise AND is represented as ‘&’ and the logical operator is represented as ‘&&’. There are some fundamental differences between them. These are as follows −
- The logical AND operator works on Boolean expressions, and returns Boolean values only. The bitwise AND operator works on integer, short int, long, unsigned int type data, and also returns that type of data.
Example
#include<iostream> using namespace std; int main() { int x = 3; //...0011 int y = 7; //...0111 if (y > 1 && y > x) cout << "y is greater than 1 AND x" << endl; int z = x & y; // 0011 cout << "z = "<< z; }
Output
y is greater than 1 AND x z = 3
- The && operator does not evaluate second operand if first operand becomes false. Similarly, || operator does not evaluate second operand when first one becomes true, but bitwise operators like & and | always evaluate their operands.
Example
#include<iostream> using namespace std; int main() { int x = 0; cout << (x && printf("Test using && ")) << endl; cout << (x & printf("Test using & ")); }
Output
0 Test using & 0
- Related Articles
- What are the differences between Physical and Logical Topology?
- What are the logical operators in C#?
- What are bitwise operators in C#?
- Relational and Logical Operators in C
- What are the logical operators in Java?
- What are Logical Operators in JavaScript?
- What are the bitwise operators in Java?
- C# Bitwise and Bit Shift Operators
- What are JavaScript Bitwise Operators?
- Differences between & and && operators in Java.
- Differences between | and || operators in Java
- Logical Operators in C++
- What types of logical operators are in javascript?
- Bitwise Operators in C
- Bitwise Operators in C++

Advertisements