C Language Study Notes (2)

Source: Internet
Author: User

C language type conversion:

1. example:

Int;

A = 3.2 + 3/4.0; // first convert to double, get 0.75

// 3.2 + 0.75 = 3.95

// Because a is an integer, the final result is determined by the type of a (that is, the type on the left of the equal sign), and the result is 3.

2. implicit conversion:

A. Operation conversion-when different types of data are mixed;

B. Value assignment conversion-when a value is assigned to a variable of different types;

C. output conversion-convert the output to the specified output format;

D. function call -- convert if the input parameter type is inconsistent.

  

Operation conversion:

(A) automatic conversion of char and short> int,

(B) float automatic conversion> double

Only int and double types are involved in mathematical operations. The return values of all mathematical function names are of the double type.

3.

Example:

Double x = 3.4;

(Int) x;

First, eight bytes are allocated as the space of x in the memory stack, and 3.4 bytes are stored in the constant zone. Then four bytes are allocated in the temporary space, store "3" in these four bytes. The required intermediate variable is obtained by force type conversion, and the original variable value remains unchanged.

4. ++, -- (post): Run after use

Int a [10];

Int * p =;

M = * p ++; // => m = * (p ++ );

Equivalent to m = * p; p ++;

++ (Post) and * are both in the same priority. The combination order is from right to left.

5. In C language, "=" is an operator and has an operation result. Its operation result is the same as its left value.

Example:

B = a = 2; Calculate a = 2 first, and then assign the result of the operator a = 2 to B.

Example:

Int;

A = 10;

Here there is an operation conversion, because 10 is a constant of the short type, and is converted to the int type after being assigned to.

6. ",": comma operator. Its value is the value of the last expression.

7. int main (): The returned value is "0". If an error occurs, a non-zero value is returned.

8. I/O Buffer

A. The buffer is full.

B. When the file is closed, buffer --> Disk

C. flush () Strong brush Buffering

D. When the program crashes, it will not be written to the disk.

9. Exchange two pieces of data with the minimum space

Int a, B; int a, B, temp;

A = a + B; temp =;

B = a-B; <= a = B;

A = a-B; B = temp;

Exchange two numbers in the shortest way with the least space

Int a, B;

A = a ^ B;

B = a ^ B;

A = a ^ B;

Because two identical numbers '^' are zero, such as a ^ B = B; => 0 ^ B = B;

10.

Int main ()

{

Int * p; // This is incorrect. p is a null pointer.

Scanf ("% d", p );

}

  

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.