FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
544 views
in Tutorial & Interview questions by Goeduhub's Expert (9.3k points)

Relational operators check if a specific relation between two operands is true. The result is evaluated to 1 (which means true) or 0 (which means false). This result is often used to affect control flow (via if, while, for), but can also be stored in variables.

1 Answer

0 like 0 dislike
by Goeduhub's Expert (9.3k points)
 
Best answer

Relational operators check if a specific relation between two operands is true. The result is evaluated to 1 (which means true) or 0 (which means false). This result is often used to affect control flow (via if, while, for), but can also be stored in variables.

Equals "==" 

Checks whether the supplied operands are equal.

1 == 0;                   /* evaluates to 0. */

== 1;                 /* evaluates to 1. */

int x = 5; 

int y = 5;

int *xptr = &x, *yptr = &y;

xptr == yptr;        /* evaluates to 0, the operands hold different location addresses. */

*xptr == *yptr; /* evaluates to 1, the operands point at locations that hold the same value. */

Attention: This operator should not be confused with the assignment operator (=)! 

Not equals "!=" 

Checks whether the supplied operands are not equal.

1 != 0;                          /* evaluates to 1. */

!= 1;                    /* evaluates to 0. */

int x = 5; int y = 5;

int *xptr = &x, *yptr = &y;

xptr != yptr;        /* evaluates to 1, the operands hold different location addresses. */

*xptr != *yptr; /* evaluates to 0, the operands point at locations that hold the same value. */

This operator effectively returns the opposite result to that of the equals (==) operator. 

Not "!" 

Check whether an object is equal to 0. 

The ! can also be used directly with a variable as follows:

!someVal

This has the same effect as:

someVal == 0

Greater than ">" 

Checks whether the left hand operand has a greater value than the right hand operand

5 > 4                             /* evaluates to 1. */

5                        /* evaluates to 0. */

4                        /* evaluates to 0. */

Less than "<" 

Checks whether the left hand operand has a smaller value than the right hand operand

5 < 4                              /* evaluates to 0. */

5                        /* evaluates to 1. */

4                       /* evaluates to 0. */

Greater than or equal ">=" 

Checks whether the left hand operand has a greater or equal value to the right operand.

5 >= 4                                 /* evaluates to 1. */

>= 5                          /* evaluates to 0. */

>= 4                        /* evaluates to 1. */

Less than or equal "<=" 

Checks whether the left hand operand has a smaller or equal value to the right operand.

5 <= 4                               /* evaluates to 0. */

<= 5                         /* evaluates to 1. */

<= 4                        /* evaluates to 1. */

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

0 like 0 dislike
1 answer 267 views
0 like 0 dislike
1 answer 265 views
0 like 0 dislike
0 answers 258 views
0 like 0 dislike
1 answer 602 views
0 like 0 dislike
1 answer 335 views

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...