Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Assignment, Comparison, Not Equal To | Operators
C Basics
course content

Course Content

C Basics

C Basics

1. Introduction
2. Data
3. Operators
4. Control Statements
5. Functions
6. Pointers

book
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 represents true;
  • 0 represents false.

Note

The binary values 0 and 1 can also represent states. We've already encountered these values when discussing byte states in a previous lesson.

For instance, with the != operator:

c

Main

copy
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:

c

Main

copy
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.

What is the output of the next code?

What is the output of the next code?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 1
We're sorry to hear that something went wrong. What happened?
some-alt