Dark Horse programmer--c Language operator

Source: Internet
Author: User

Java training, Android training, iOS training,. NET training, look forward to communicating with you!

1. Arithmetic operations

1) Addition operation: +, besides can do addition operation, can also represent a positive sign, such as +4

2) Subtraction:--except for subtraction, minus, 9

3) Multiplication: *, note symbol, not X, but *

4) Division operation:/, note the symbol, not ÷, nor \, but/. The integer divided by an integer or an integer. The value of 1/2 is 0, and this is not one-second.

5) Take rest operation:%, take two integers after dividing the remainder. Note:% can only be integers, positive and negative depending on the value of the left of%

Note the point:

"Int a=10.8;//data precision loss warning. Result for 10--automatic type conversion

"int a= (int) 10.8;//no warning. Cast 10.8 to integral type--coercion type conversion

"Double c=10.6+6//result is 16.600000. In a computer, with two numeric values, the values on both sides of the operator need to be of the same type and are automatically type promoted if different. That is, convert 6 to 6.000000 and then participate in the operation.

The number of two numbers involved in the operation is what type, then the result is what type. An int A=10/3 result of 3,double B=10/3 results in a 3.000000;double C=10.0/3 result of 3.333333. An exact value is required to enforce type conversions. Double d= (double) 3/2 converts 3 to a double type to 3.000000, then 2 for automatic type promotion to 2.000000 participation, and 1.500000 for the result. Can also be written as 3/(double) 2. This situation requires attention to the difference from casting to the whole double e= (double) (3/2) is the first to calculate the value of 3/2 to 1 and then to 1 to force the type conversion, the result is 1.000000

2. Self-increment self-reduction

++a: First add 1, then participate in the operation

a++: First participate in the operation, then add a plus 1

3.sizeof

Used to calculate the number of bytes of memory for a variable or a constant, a data type.

How to use: sizeof (variable \ constant) or sizeof variable \ constant

sizeof (data type), but cannot be the sizeof data type

4. Relational operators The relational operators are: =,! =,;, <, >=, <=.    where = =,! = have equal priority for,<, <=, >, >=, and the priority of the former is lower than the second. The relationship operator is in the direction of "left to right", and the precedence of the relational operator is less than the arithmetic operator 5. Logical operators

The result of a logical operation is only two: true (0) and False (1)

"and &&: conditions 1&& conditions 2 only the condition 1 and Condition 2 are established, only for true otherwise false."

"or | | : Condition 1 | | Condition 2 When one of the conditions 1 or Condition 2 is true, it is false when it is not established.

"No!" : ! Conditions, take the reverse

Note: When a logical operator is operating, the following conditions are ignored, as long as the integrity of the whole can be determined.

Int a=b=10;

Int c= (a>5) && (++b>=11);//At this time a==10,b==11,c==1

Int c= (a<5) && (++b>=11);//At this time a==10,b==10,c==0

Tip: If you don't know the priority of each symbol when doing a logical operation, you can use ()

6. Three mesh operator

"Binocular: Requires two values to participate in the operation

Monocular: A numeric participation operation

Trinocular: Requires 3 values to participate

"Format: Conditions?" Value 1: Value 2

Judge first? Before the conditions, if the condition is set to return a value of 1, if the condition is not established, return to the condition 2.

If the values of a and B are required to be compared, a large value is deposited in C: c=a>b?a:b

Compare the values of the A,b,c three numbers and deposit the maximum values in D: int abmax= (a>b)? a:b; d=abmax>c:abmax:c;

Java training, Android training, iOS training,. NET training, look forward to communicating with you!

Dark Horse programmer--c Language operator

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.