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:
int x = 5; // Assigns the value 5 to variable `x`
int y = 8; // Assigns the value 8 to variable `y`
x = y; // Assigns the value of `y` to `x` (so now, `x` is 8)
Comparison Operators (!=, ==)
Let's delve into how these work:
int result = (50 != 2);
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.c
12345678910#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.c
12345678910#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.
Grazie per i tuoi commenti!
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Awesome!
Completion rate improved to 2.63
Assignment, Comparison, Not Equal To
Scorri per mostrare il menu
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:
int x = 5; // Assigns the value 5 to variable `x`
int y = 8; // Assigns the value 8 to variable `y`
x = y; // Assigns the value of `y` to `x` (so now, `x` is 8)
Comparison Operators (!=, ==)
Let's delve into how these work:
int result = (50 != 2);
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.c
12345678910#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.c
12345678910#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.
Grazie per i tuoi commenti!