C # Language Basics Operators

Source: Internet
Author: User

Operator classification, precedence

Operator:
First, the mathematical operator:
+,-,*,/,++,--

Example 1:

Example 2:

Example 3:


1. Increment operator : + +
(1) Prefix increment operator
int x=4;
x++;//output, the value of X is 5

Example:


(2) Postfix increment operator
int x=4;
++x;//output, the value of X is 5


The difference between the prefix increment operator and the postfix increment operator:
①int y=++x;
equivalent to x=x+1;
int y=x;
②int y=x++;
equivalent to int y=x;
x=x+1;
2. Decrement operator :--
The same increment operator.

Example:


Two, the relationship operator, a total of 6. Returns only Ture or false.
= =,! =, <,>, <=, >=

Note: A "=" is an assignment, and 2 "= =" means equal

Example:


Three, a total of 3 logical operators.
&& (with) | | (OR)! Non-

Example:


Iv. Assignment operators
=, + =,-=, *=,%=,/=

Example:


Five, the conditional operator ()? ():()
Example: x= (x>12)? (x-12):(x);
If x>12, then x=x-12, otherwise x=x. Judge true, False

C # Language Basics Operators

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.