iOS Development Learning Note 002

Source: Internet
Author: User

Operator

There are 34 kinds of operators in C language, and subtraction are common.

Arithmetic operators

1, plus

10+2

2, reduce

20-2

3. Multiply

12*2

4, in addition to

10/2

5. Take surplus

10%3 = 1;

10%-3 = 1;

-10%3 =-1;

-10%-3 =-1;

  The result of the remainder is only related to the value on the left, regardless of the right value.
Note: type conversions

Automatic type conversion

int a = 10.99;//a is 10, a warning message pops up

Forcing type conversions

int a = (int) 10.99;//This is also 10, no warning message

Automatic type Promotion

Doble d = 10.99 + 6;//operation converts 6 to double type

Assignment operation =

int a = 10;//= is the assignment operator

The left side of the equals sign cannot be a constant.

 Compound assignment operator +=,-+,*=,/=,%=

int a = 10;

A +=10;//equivalent to a = a +10;

A *=20;//equivalent to a = a * 20;

a+= 2+2+10; a+= (2+2+10); Default to the right as a whole

Self-increment self-decrement operator--+ +

int a=10;

int b;

b = a++;//First uses a and then self-increment, so B is 10,a to 11

b = ++a;//First self-increment and then use a, so a first becomes 12,b to 12

sizeof operator

Calculate the number of bytes in memory of a variable

int a = 10;

int size = sizeof (a); sizeof A; You can write that too.

printf ("%d", size);

Relational operations

1. Condition judgment

Judging whether the condition is set up as true and not set up as false.

  Any value other than 0 is true, and only 0 is false. Any value has a true or false nature.

2. Relationship Comparison

  >,<,>=,<=, ==,!=

The condition is set to return 1, not set to return 0.

Note: priority

[<,<=,>,>=] > [!=,==], operations from left to right

int a = 10>9+1;//a=0

logical operators

with &&, or | |, not!

1. Logic and &&

Condition 1 && Condition 2;//also established return 1, otherwise return 0

Conditions are only enforced if condition 1 is established 2

2. Logic or | |

Condition 1 | | Condition 2;//As long as there is a set up on return 1, are not established return 0

Condition 2 will not execute as long as condition 1 is established

3, logical Not!

! Conditional 1;//Reverse

int a =!! 10;//can be used continuously

The three-mesh operator condition? Value 2: Value 3;

If the condition is true, the value 2 is returned, otherwise the value 3 is returned.

int a = 10>8?10:8;

2015-4-9, today, tomorrow remains.

iOS Development Learning Note 002

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.