0% found this document useful (0 votes)
12 views

Basic Operators in C Programming Language (Cont

The document discusses relational and logical operators in C programming. Relational operators are used to compare values and include equality (==), inequality (!=), greater than (>), less than (<), greater than or equal to (>=), and less than or equal to (<=) operators. Logical operators determine logical relations between variables and include logical AND (&&), logical OR (||), and logical NOT (!) operators. Examples are provided to demonstrate the use of each operator type in if statements to evaluate conditions and return true or false.

Uploaded by

janlixalmendral
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Basic Operators in C Programming Language (Cont

The document discusses relational and logical operators in C programming. Relational operators are used to compare values and include equality (==), inequality (!=), greater than (>), less than (<), greater than or equal to (>=), and less than or equal to (<=) operators. Logical operators determine logical relations between variables and include logical AND (&&), logical OR (||), and logical NOT (!) operators. Examples are provided to demonstrate the use of each operator type in if statements to evaluate conditions and return true or false.

Uploaded by

janlixalmendral
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Basic Operators in C Programming Language

(Cont)
Relational Operators or Comparison Operators
These are used for comparison of the values of
two operands.

For example, checking if one operand is equal to


the other operand or not, an operand is greater
than the other operand or not etc. Some of the
relational operators are (==, >= , <= ).
Example1: == (Equal to)

#include <stdio.h>
int main()
{
int x=5;
int y=3;

if (x==y)
{
printf("True\n" );
}
else
{
printf("False\n" ); // return false because 5 is not equal to 3
}
}
Example1: != (Not equal)

#include <stdio.h>
int main()
{
int x=5;
int y=3;

if (x!=y)
{
printf("True\n" );
}
else
{
printf("False\n" ); // return true because 5 is not equal to 3
}
}
Example1:>(Greater than )

#include <stdio.h>
int main()
{
int x=5;
int y=3;

if (x>y)
{
printf("True\n" );
}
else
{
printf("False\n" ); // returns true because 5 is greater than 3
}

}
Example1:<(Less than )

#include <stdio.h>
int main()
{
int x=5;
int y=3;

if (x<y)
{
printf("True\n" );
}
else
{
printf("False\n" ); // returns false because 5 is not less than 3
}

}
Example1: >=(Greater than or equal to)

#include <stdio.h>
int main()
{
int x=5;
int y=3;

if (x>=y)
{
printf("True\n" );
}
else
{
printf("False\n" ); // returns true because 5 is greater, or equal, to 3
}

}
Example1:<=(Less than or equal to)

#include <stdio.h>
int main()
{
int x=5;
int y=3;

if (x<=y)
{
printf("True\n" );
}
else
{
printf("False\n" ); // returns false because 5 is neither less than or equal to 3
}

}
Logical Operators
Logical operators are used to determine the logic
between variables or values.
Example1: && (Logical and)

#include <stdio.h>
int main()
{
int x=5;

if( x> 3 && x < 10)


{
printf("True\n" );
}
else
{
printf("False\n" ); // returns true because 5 is greater than 3 AND 5 is less than
10

}
Example1: || (Logical or)

#include <stdio.h>
int main()
{
int x=5;

if( x> 3 || x < 4)


{
printf("True\n" );
}
else
{
printf("False\n" ); // returns true because one of the conditions are true (5 is
greater than 3, but 5 is not less than 4)

}
Example1: !(Logical not)

#include <stdio.h>
int main()
{
int x=5;

if(!(x> 3 || x < 10))


{
printf("True\n" );
}
else
{
printf("False\n" ); // returns false because ! (not) is used to reverse the result

You might also like