C-Language Summary (6)

Source: Internet
Author: User

1. Expression:

An arithmetic expression:

Monocular: +,-, + +,--。

Binocular: +,-,*,/,%.

An assignment expression:

Simple assignment: =

Compound assignment: +=,-=,*=,,/=%=,!=.

Relational Expressions:

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

Logical expression:

! , &&,| |

Conditional expression:?

Comma-expression:,

Other operations: sizeof

2.++ operator

Self-increment, the decrement operator increases the value of the variable by 1 or minus 1.

Available in four different forms: i++ ++i I----I

The difference between i++ (i--) and ++i (-i):

The value of I is added (minus) 1 after performing the self-increment (minus) operation

However, the value of the expression is different: the value of i++ (i--) is the original value.

The value of ++i (-i) is the value after increment (minus) 1.

Attention:

The self-increment operator (+ +), the decrement operator (--) can be used only for variables, not constants or expressions.

+ + and--the combination of the direction is "from right to left."

3. Conditional expressions

Exp1? Exp2:exp3

Cases:

[If (x>0)

y=x+2; ===== [Y= (x>0) x+2:x*x]

Else

Y=x*x;]

4. Comma-expression

Expression 1, expression 2, Expression 3 ..... Expression n

The expression 1 is evaluated first, and then the expression 2 is evaluated .... And the value of the expression n as the value of the comma expression.

Int A,b,c;

(a=2), (b=3), (C=A+B);

The comma operator has the lowest priority and the left combination.

5. Other operations

Length operator: sizeof

Monocular operator, calculating the byte length of a variable or data type

Int A;

Sizeof (a)

The length of the shaping variable A, value 4 (bytes)

Sizeof (int)

Length of the shaper, Value 4 (bytes)

6. Definitions and references for a set of arrays

Definition of one-dimensional array

1. How to define:

Type an array group name [shaping constant expression];

Int A[10];

2. Description:

A, the naming and variable names of the array names are the same, followed by the identifier naming rules.

B, the constant expression after the array name is enclosed in [].

C, the constant expression represents the number of elements, that is, the array length.

Example: a[10] means that the array a contains 10 elements, respectively, a[0]-a[9]

3. The array must first be defined and then used. The C language specifies that the entire array can only be referenced one at a time.

4, initialization of array elements can be implemented in the following ways:

A, the array element is assigned an initial value when it is defined. such as: int a[10]={0,1,2,3,4,5,6,7,8,9};

B, you can assign values to a subset of elements. such as: int a[10]={0,1,2,3,4}, indicates that only the first five elements are assigned an initial value, the last five elements are automatically assigned to 0 values.

C, no initial value is assigned to the static array, and the system automatically assigns 0 values to all elements. That is: If you want to make the value of all elements in array a 0, you can define the array as follows: Static int a[5];

C-Language Summary (6)

Related Article

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.