C - IntroductionC - Hello World ProgramC - Exercise 1C - Basic structure of a C programC - TokensC - Data TypesC - Type ConversionC - Exercise 2C - Character Input Output OperationsC - Input Output operation using scanf and printf functions

Operators

C - Arithmetic OperatorsC - Relational OperatorsC - Logical OperatorsC - Assignment OperatorsC - Increment Decrement OperatorsC - Bitwise Operators

Precedence and Associativity

C - Precedence and AssociativityC - Exercise 3

Conditions

C - If Else decision making statementsC - Switch Case decision making statements

Loop

C - While LoopC - Do While LoopC - For LoopC - Exercise 4

Array

C - ArraysC - Two Dimensional ArraysC - Multi Dimensional ArraysC - Exercise 5

String

C - StringC - Exercise 6C - String Manipulation

Functions

C - FunctionsC - Functions CategoryC - Function Call - Flow of ControlC - RecursionC - Functions and ArraysC - Functions and Strings

Structures

C - StructuresC - Structures and ArraysC - Passing structure to functionC - Function returning structureC - Structure in Structure

Pointers

C - PointersC - Pointers and VariablesC - Pointers and Variables Memory RepresentationC - Pointers Chaining

Pointers and Arrays

C - Pointers and One Dimensional ArrayC - Pointers and Two Dimensional ArrayC - Array of Pointers

Pointers and Strings

C - Pointers and Strings

Pointers and Functions

C - Pointers and Functions - Call by Value and Call by ReferenceC - Function returning pointer

Pointers and Structures

C - Pointers and StructuresC - Pointers and Array of StructuresC - Passing structure pointer to function

Handling Files

C - File Handling - Getting StartedC - File Handling - Read and Write CharactersC - File Handling - Read and Write IntegersC - File Handling - Read and Write multiple dataC - File Handling - Randomly Access Files

Command Line Arguments

C - Command Line Arguments

Dynamic Memory Allocation

C - Dynamic Memory Allocation - Getting StartedC - Dynamic Memory Allocation - malloc functionC - Dynamic Memory Allocation - calloc functionC - Dynamic Memory Allocation - realloc function

C - Relational Operators

C Programming

In this tutorial we will learn about relational operators in C programming language.

C provides us with 6 relational operators.

OperatorDescription
<Is less than
<=Is less than or equal to
>Is greater than
>=Is greater than or equal to
==Is equal to
!=Is not equal to

We use relational operators to compare two quantities. If the condition is satisfied then we get one (true) otherwise, it is zero (false).

Is less than

In the following example we have two numbers and we are checking if a is less than b.

#include <stdio.h>
int main(void)
{
  int
    a = 10,
    b = 20;
    
  if (a < b) {
    printf("a is less than b\n");
  }
  else {
    printf("a is not less than b\n");
  }
  return 0;
}

Output

a is less than b

Note! In the above program and in the programs that follows we are using if-else conditional statement. If the condition is true or non-zero then the if-block code is executed. Otherwise, the else-block code is executed.

We will learn more about if-else in the later tutorial.

Is less than or equal to

In the following example we have two numbers and we are checking if a is less than or equal to b.

#include <stdio.h>
int main(void)
{
  int
    a = 10,
    b = 20;
    
  if (a <= b) {
    printf("a is less than or equal to b\n");
  }
  else {
    printf("a is not less than and not equal to b\n");
  }
  return 0;
}

Output

a is less than or equal to b

Is greater than

In the following example we have two numbers and we are checking if a is greater than b.

#include <stdio.h>
int main(void)
{
  int
    a = 20,
    b = 10;
    
  if (a > b) {
    printf("a is greater than b\n");
  }
  else {
    printf("a is not greater than b\n");
  }
  return 0;
}

Output

a is greater than b

Is greater than or equal to

In the following example we have two numbers and we are checking if a is greater than or equal to b.

#include <stdio.h>
int main(void)
{
  int
    a = 20,
    b = 10;
    
  if (a >= b) {
    printf("a is greater than or equal to b\n");
  }
  else {
    printf("a is not greater than and not equal to b\n");
  }
  return 0;
}

Output

a is greater than or equal to b

Is equal to

In the following example we have two numbers and we are checking if a is equal to b.

#include <stdio.h>
int main(void)
{
  int
    a = 10,
    b = 10;
    
  if (a == b) {
    printf("a is equal to b\n");
  }
  else {
    printf("a is not equal to b\n");
  }
  return 0;
}

Output

a is equal to b

Is not equal to

In the following example we have two numbers and we are checking if a is not equal to b.

#include <stdio.h>
int main(void)
{
  int
    a = 20,
    b = 10;
    
  if (a != b) {
    printf("a is not equal to b\n");
  }
  else {
    printf("a is equal to b\n");
  }
  return 0;
}

Output

a is not equal to b

Among the six relational operator, each one is a complement of another operator.

OperatorIs Complement of
<=
>=
==!=

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT