Comparison Operators In C Language

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

In C programming, comparison operators are used to compare the values of two operands and determine if a certain condition is true or false. Here are the most common comparison operators used in C:

  • == : equal to. It returns true if the values of the operands are equal.

Copy code

int x = 5, y = 3; if (x == y) {    printf("x is equal to y"); } else {    printf("x is not equal to y"); }

This will output: "x is not equal to y"

  • != : not equal to. It returns true if the values of the operands are not equal.

Copy code

int x = 5, y = 3; if (x != y) {    printf("x is not equal to y"); } else {    printf("x is equal to y"); }

This will output: "x is not equal to y"

  • > : greater than. It returns true if the value of the left operand is greater than the value of the right operand.

Copy code

int x = 5, y = 3; if (x > y) {    printf("x is greater than y"); } else {    printf("x is not greater than y"); }

This will output: "x is greater than y"

  • < : less than. It returns true if the value of the left operand is less than the value of the right operand.

Copy code

int x = 5, y = 3; if (x < y) {    printf("x is less than y"); } else {    printf("x is not less than y"); }

This will output: "x is not less than y"

  • >= : greater than or equal to. It returns true if the value of the left operand is greater than or equal to the value of the right operand.

Copy code

int x = 5, y = 3; if (x >= y) {    printf("x is greater than or equal to y"); } else {    printf("x is not greater than or equal to y"); }

This will output: "x is greater than or equal to y"

  • <= : less than or equal to. It returns true if the value of the left operand is less than or equal to the value of the right operand.

Copy code

int x = 5, y = 3; if (x <= y) {    printf("x is less than or equal to y"); } else {    printf("x is not less than or equal to y"); }

This will output: "x is not less than or equal to y"

It's important to note that comparison operators return a Boolean value (true or false) and can be used in conditional statements (if, else, switch, etc.) and loops (while, for, etc.) to control the flow of the program based on the result of the comparison.

4. Operators

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?