Зміст курсу
C Basics
C Basics
Assignment, Comparison, Not Equal To
We've learned how to store data in variables, organize data into arrays, and display data as strings. Yet, we haven't explored how to modify or manipulate that data.
Assignment Operator (=)
We're already familiar with this operator. It assigns the value on the right to the variable on the left:
Comparison Operators (!=, ==)
Let's delve into how these work:
The expression (50 != 2)
evaluates to either true
(1) or false
(0), depending on the validity of the comparison.
The !=
operator stands for "not equal".
If 50
isn't equal to 2
, then (50 != 2)
evaluates to true.
In computing, the notions of "true" and "false" are numerically represented as 1
(true) and 0
(false):
1
representstrue
;0
representsfalse
.
Note
The binary values
0
and1
can also represent states. We've already encountered these values when discussing byte states in a previous lesson.
For instance, with the !=
operator:
Main
#include <stdio.h> int main() { int result = (50 != 2); printf("%d", result); return 0; }
The expression (50 != 2)
evaluates to true, or 1
.
The ==
operator checks for equality.
For instance:
Main
#include <stdio.h> int main() { int result = (50 == 2); printf("%d", result); return 0; }
The expression (50 == 2)
is false, or 0
, because 50 is not equal to 2.
Дякуємо за ваш відгук!