Relive C + + (ii)

Source: Internet
Author: User
Tags arithmetic arithmetic operators control characters logical operators

---restore content starts---

Array---restore content starts---

format Control characters :

%x: Output or read in 16 binary form;

%u: Unsigned output or read-in

Cin cout and scanf printf, a program do not mix the two;

operators : Assignment operators, arithmetic operators, relational operators, logical operators;

Assignment operator: =,+=,-=,*=,/=,%=

Arithmetic operators: +,-, *,/,%,++,--arithmetic operations, if there is overflow, then the overflow part is taken off (floating point type of unpredictable), such as int i=0xffffffff,j;j=i+3; J=0X100000002;J is of type int, 4 bytes, j=2; Note that calculations may not overflow, but there is overflow in the middle of the calculation, such as the calculation of printf ("%d", (A+B)/2), and if the result C of the A+B calculation is outside the int range, the calculation will go wrong . The type of division calculation is consistent with the type of high precision in the operand.

Relational operators: = = = = > < >= <= returns the bool type,

Logical operator:&& | |  ! Short-circuit calculation, that is, the calculation of the results can be predicted, not backward calculation;

Order of Operations : generally available () to make the precedence operation

Conditional structure: If else, there are multiple adjacent if else, else matches the nearest if,

If else is too large, the switch statement can be selected as appropriate.

switch (expression) {//Expression return type can only be integer type int, char (char type is actually ASCII value)

case constant Expression 1:

Break

case constant Expression 2

Break

....

}

Loop structure : For loop, for (expression 1; expression 2; expression 3) {statement Group; }

The expression in the For loop can be not written in all, but ";" To be preserved.

do{loop Body;} while (condition) loop, first loop in judging condition

Break: Jump out of the nearest loop body;

Continue: To the head of the loop, after the statement is not executed, if for loop, for (int i=0;i<n;i++), expression 3:i++ will execute

Array:


Definition: Type an array group name [number of elements], the number of elements must be a constant or constant expression; arrays are stored in memory continuously

T A[n] occupies a space of n*sizeof (t), Byte, array name a refers to the first address stored in the array, assuming p, A[n] stores the address p+n*sizeof (int),

Sieve method to calculate prime number:

The initialization of an array of int arr[10]={1,2,3,4} is not given the default value of binary 0,

Array subscript out-of-bounds compilation does not error, the operation may be error, because the operating system may not allow the write of out-of-bounds memory.

Two-dimensional arrays:

Two-dimensional arrays are also contiguous in memory for two-dimensional array initialization int a[2[3]={(4,5,6)}

If each row is initialized, you can write the number of rows int a[][3]={(4,5,6)}

Relive C + + (ii)

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.