
- 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
Relational and Logical Operators in C
Relational Operators
Relational operators are used to compare two values in C language. It checks the relationship between two values. If relation is true, it returns 1. However, if the relation is false, it returns 0.
Here is the table of relational operators in C language
Operators | Operator Name |
---|---|
== | Equal to |
> | Greater than |
< | Less than |
!= | Not equal to |
>= | Greater than or equal to |
<= | Less than or equal to |
Here is an example of relational operator in C language
Example
#include <stdio.h> int main() { int x = 10; int y = 28; if(x==y) printf("Both variables are equal
"); if(x>y) printf("x is greater than y
"); if(x<y) printf("x is less than y
"); if(x!=y) printf("x is not equal to y
"); if(x<=y) printf("x is lesser or equal to y
"); if(x>=y) printf("x is greater or equal to y
"); return 0; }
Output
x is less than y x is not equal to y x is lesser or equal to y
Logical Operators
Logical operators are used to perform logical operations. It returns 0 or 1 based on the result of condition, whether its true or false. These operators are used for decision making in C language.
Here is the table of logical operators in C language,
Operators | Meaning of Operators | Results |
---|---|---|
&& | Logical AND | True when all operands are true |
|| | Logical OR | True only if either one operand is true |
! | Logical NOT | True when operand is zero |
Here is an example of logical operators in C language,
Example
#include <stdio.h> int main() { int x = 10; int y = 28; int a = 15; int b = 20; if(x<y && a==b) printf("x is less than y AND a is equal to b
"); if(x<y || a==b) printf("x is less than y OR a is equal to b
"); if(!x) printf("x is zero
"); return 0; }
Output
x is less than y OR a is equal to b
- Related Articles
- How to implement relational and logical operators in JShell in Java 9?
- Relational and comparison operators in C++
- C++ Relational and Equality Operators
- Relational Operators in C++
- Logical Operators in C++
- What are relational operators in C#?
- Logical Operators on String in C#
- Extended Operators in Relational Algebra in C++
- Relational Operators on STL Array in C++
- What are relational operators in C language?
- Written version of Logical operators in C++
- What are the logical operators in C#?
- Java Relational Operators
- Python Logical Operators
- Java Logical Operators

Advertisements