MMGames Introduction to C C Language Development Environment C language now Useful Apps Contact Us
MMGames

Automatic version identification

SpineViewer

It's easy to tell by looking at it.

Response Time Checker

I can leave my computer on and do it.

Mouse cleaning time

I can leave my computer on and do it.

Mouse cleaning time

C language learned by suffering
C language learned by suffering

Operators for comparison

equivalence operator
The == operator was introduced in the previous section, and this line of operators is called the equality operator.
Two types of equality operators are available

Symbols turn out to be true False.
Two values are equal Two values are not equal
! = ! Two values are not equal Two values are equal

These operators are used to compare whether values are equal or not.
The following program determines if the number entered is 10.

source code
 #include <stdio.h>

int main(void)
{
    int suuti;
    scanf("%d", &suuti);
    if (suuti == 10)
        printf("Input value is 10. \n");
    if (suuti ! = 10)
        printf("Input value is not 10. \n");
    return 0;
}

If you let this program run and enter 10, the result will be as follows

Execution Result
10 Data input
Input value is 10.

If you run this program and enter anything other than 10, the results will be as follows

Execution Result
135 Data input
Input value is not 10.


Since it is an operator
This comparison operator, as well as the relation and logical operators described next, are also operators.
That is, they can be placed in formulas and used in calculations as usual.

The following equation computes the value of the variables val1 and val2 as
If they are equal, answer is set to 1 (in many compilers), and
If they are not equal, 0 is assigned.
answer = val1 == val2;

Some advanced users prefer to do it this way.
It is not easy to understand and is not recommended.

relational operator
While the equality operator was an operator to check if two values are equal, the
The relational operator is an operator that examines the relationship between two values.

Symbols turn out to be true False.
< Left value is less than right Left value is not less than right
> Left value is greater than right Left value is not greater than right
<= Left value is less than or equal to right Left value is not less than right
>= Left value is greater than or equal to right Left value is not greater than right

It probably goes without saying by now, but the difference between small and
The difference is whether it includes or excludes equality. Less than & greater than return true even when they are equal.

These operators are used to test the relationship between two values.
The following program determines if the number entered is greater than 10.

Source Code
 #include <stdio.h>

int main(void)
{
    int suuti;
    scanf("%d", &suuti);

    if (suuti == 10)
        printf("Input value is 10. \n");

    if (suuti > 10)
        printf("Input value is greater than 10. \n");

    if (suuti < 10)
        printf("Input value is less than 10. \n");

    return 0;
}

If you let this program run and enter 10, the result will be as follows

Execution Result
10 Data input
Input value is 10.

If you let this program run and input greater than 10, the results will be as follows

Execution Result
135 Data input
Input value is greater than 10.

If you let this program run and input less than 10, the result will be as follows

Execution Result
5 Data input
Input value is less than 10.

logical operator
The logical operators have slightly different properties than the previous operators, and are
It can be used to merge multiple conditions or to reverse a decision.

Symbols Meaning become true False.
&& AND Both right and left conditions are true Either one of the right or left condition is false
|| or (OR) Either one of the right or left condition is true Both right and left conditions are false
! NO (NOT) Condition is false Condition is true

In an if statement, you can only make a decision on one condition at a time.
These operators make it possible to make decisions based on multiple conditions.
The following program determines if the number entered is between 8 and 12.

Source code
 #include <stdio.h>

int main(void)
{
    int suuti;
    scanf("%d", &suuti);

    if (suuti >= 8 && suuti <= 12)
        printf("Between 8 and 12. \n");

    if (! (suuti >= 8 && suuti <= 12))
        printf("Not between 8 and 12. \n");

    return 0;
}


If you let this program run and enter between 8 and 12, the results will be as follows

Execution Result
9 Input data
8-12.

If you run this program and enter anything other than between 8 and 12, the results will be as follows

Execution Result
3 Data input
Not between 8 and 12.

The point of this program is in the conditional part of the if statement.
Since the "if" statement allows only one condition, it is not possible to determine the condition of 8 or more and 12 or less in the usual way.
However, by using the && operator, it is possible to make a decision based on two conditions.

Also, the second if statement's decision is the same as the first one with ! operator.
! operator has the function of reversing the result of a decision, so the
The result is exactly the opposite of the first if statement.


About this Site

The C language (bitter C), which is learned by suffering, is
This is the definitive C language introductory site.
It systematically explains the basic functions of the C language and
It is as complete as or better than any book on the market.

Part 0: Program Overview
  1. What is the program?
Chapter 2: How to write a program
  1. Writing Rules
  2. Writing conventions
  3. Exercise 2
Chapter 3: Display on Screen
  1. String display
  2. newline character
  3. Exercise 3
Chapter 4: Numeric Display and Calculation
  1. Numeric Display
  2. Basic Calculations
  3. Type of value
  4. Exercise 4
Chapter 5: Numerical Memory and Calculation
  1. Memorize values
  2. Variable Type
  3. Type conversion
  4. Numeric justification
  5. Exercise 5
Chapter 6: Input from the keyboard
  1. Functions for input
  2. Fear of Input
  3. Exercise 6
Chapter 9: Repetition with a fixed number of times
  1. Sentences that repeat themselves
  2. Loop Operation Mechanism
  3. Exercise 9
Chapter 10: Unknown number of repetitions
  1. Loop of unknown frequency
  2. input check
  3. Exercise 10
Chapter 13: Handling Multiple Variables at Once
  1. Multiple variables are handled together.
  2. How to use arrays
  3. Exercise 13
Chapter 19: Dynamic Arrays
  1. Create arrays at will
  2. Exercise 19
Chapter 20: Multiple Source Files
  1. Minimal division
  2. The Stone of Partition
  3. Exercise 20

Comment
COMMENT

Open the 💬 comment submission box