This operator is used in c++ to represent equality.
Kenneth Leroy Busbee Show OverviewAssignment sets and/or re-sets the value stored in the storage location denoted by a variable name.[1] Equality is a relational operator that tests or defines the relationship between two entities.[2] DiscussionMost control structures use a test expression that executes either selection (as in the: if then else) or iteration (as in the while; do while; or for loops) based on the truthfulness or falseness of the expression. Thus, we often talk about the Boolean expression that is controlling the structure. Within many programming languages, this expression must be a Boolean expression and is governed by a tight set of rules. However, in many programming languages, each data type can be used as a Boolean expression because each data type can be demoted into a Boolean value by using the rule/concept that zero and nothing represent false and all non-zero values represent true. Within various languages, we have the potential added
confusion of the equals symbol If (pig = 'y') Output "Pigs are good" Else Output "Pigs are bad." The test expression of the control structure will always be true because the expression is an assignment (not the relational operator of
If (pig == 'y') Output "Pigs are good" Else Output "Pigs are bad." This example reminds you that you must be careful in creating your test expressions so that they are indeed a question, usually involving the relational operators. Some programming languages will generate a warning or an error when an assignment is used in a Boolean expression, and some do not. Don’t get caught using assignment for equality. References
Improve Article Save Article Improve Article Save Article = operator The “=” is an assignment operator is used to assign the value on the right to the variable on the left. For example: a = 10; b = 20; ch = 'y'; Example:
== operator The ‘==’ operator
checks whether the two given operands are equal or not. If so, it returns true. Otherwise it returns false. 5==5 This will return true. Example:
Output: a and b are not equal The differences can be shown in tabular form as follows:
What is the equality operator in C?Both operands of any relational or equality operator can be pointers to the same type. For the equality ( == ) and inequality ( != ) operators, the result of the comparison indicates whether the two pointers address the same memory location.
What is == used for in C?The equal-to operator ( == ) returns true if both operands have the same value; otherwise, it returns false .
Which type of operator == is?Relational Operators
== (Equal to)– This operator is used to check if both operands are equal.
What is the == operator used for?= Equal Sign
This operator assigns a value to a variable or property. Comparison operator also used as an equal to; the result of comparison operators is usually a logical value, either true or false.
|