Go to your University || Python Lab || DSA Lab || AI & Machine Learning Lab || Linux Lab || OOPs Lab || DBMS Lab || JAVA Lab ||| Free Online Tutorials ||| 
companies for Campus Placement || Logical Reasoning || Quantitative Aptitude || General English || Technical-MCQ and Interview Questions || HR Interview Questions
0 like 0 dislike
7 views
in Tutorial & Interview questions by Goeduhub's Expert (7.8k 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 (7.8k 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. */

Related questions

0 like 0 dislike
1 answer 7 views
0 like 0 dislike
1 answer 4 views
0 like 0 dislike
0 answers 14 views
0 like 0 dislike
1 answer 9 views
0 like 0 dislike
1 answer 9 views
  Realize your learning potential with courses starting at ₹ 420
 Placements:   List of companies | Logical Reasoning Questions | Quantitative Aptitude Questions | General English Questions | Technical-MCQ and Interview Questions
 Online Free Training:  MACHINE LEARNINGPython Programming | Database Management System(DBMS) | Object Oriented Programming(OOPs) using C++ | Data Structures and Algorithms(DSA) | Java Programming | Linux/Unix | C Programming
Exams: List of Exams After Graduation | List of Engineering Entrance Examinations (UG/PG) | JEE Main | JEE Advanced | GATE | IES | ISROList of PSUs
 Download Previous Year Papers For:  GATE | IES | RAJASTHAN TECHNICAL UNIVERSITY (RTU-Kota)RPSC Technical Exams | ISRO
 Goeduhub
About Us | Contact Us   Social::   |  | 
...