Home >Backend Development >C++ >How to calculate int in c language

How to calculate int in c language

下次还敢
下次还敢Original
2024-04-29 22:03:16919browse

Overview of int type calculation rules in C language: Arithmetic operators: addition, subtraction, multiplication, division, remainder, self-increment, self-decrement Assignment operators: assignment, addition, subtraction, multiplication, division, remainder, remainder, assignment comparison operators: equal to not equal to less than greater than less than equal to greater than equal to Logical operators: logical AND logical or logical NOT Bit operators: bit AND bit or bit XOR bit left shift right shift

How to calculate int in c language

C language Calculation of int type

int is the basic data type representing integer in C language and occupies 4 bytes in the computer. Its calculation rules are as follows:

Arithmetic operators:

    • ##Addition
    • Subtraction
    • Multiplication
  • / Division (return real number)
  • % Remainder (return the remainder of division)
  • Auto-increment (increase by 1)
  • -- Auto-decrement (decrease by 1)

Assignment operator:

    = Assignment
  • = Additive assignment
  • -= Subtractive assignment
  • *= Multiplicative assignment
  • / = Division assignment
  • %= Remainder assignment

Comparison operator:

    == Equal to
  • != Not equal to
  • < Less than
  • Greater than
  • <= Less than or equal to
  • = Greater than or equal to

Logical operators:

    && Logical AND
  • || Logical OR
  • ! Logical NOT

bit operator:

    & bit and
  • | bit or
  • ^ Bit XOR
  • << Bit shift left
  • Bit shift right
##Example :

<code class="c">int a = 10;
int b = 5;
int c;

c = a + b; // c 为 15
c = a - b; // c 为 5
c = a * b; // c 为 50
c = a / b; // c 为 2.0(实数)
c = a % b; // c 为 0
c++; // c 为 11
c--; // c 为 10</code>

The above is the detailed content of How to calculate int in c language. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn