C language knowledge summary, C language knowledge

Source: Internet
Author: User

C language knowledge summary, C language knowledge

Understand some variables

Familiar with some statements

Combine some functions

C Language -- "library help you write and put it in the library

The magic number changes out of thin air and does not know the meaning of the number, which affects the readability of the Code.

The parameter transfer of C speech is very special. It is a substitute.

---------------------------------------------

The main function is the entry of the C program.

# Include <stdlib. h>

System ("pause"); // pause

System ("cls"); // clear screen

Printf output system library functions

A variable is a name that represents a memory address (the size of memory occupied). This memory value can be changed in the program.

The value of a variable is the data stored in the memory.

The data type of the variable indicates the memory size occupied by the variable.

Basic Data Types in C Language

Short: short integer, 16 bits (two bytes, one byte = 8 bits)

Unsigned: 0 ~ 2 ^ 16-1 indicates a positive number

Signed:-2 ^ 8 ~ 2 ^ 8-1 indicates positive and negative numbers

Int: integer, 32bit

Unsigned: 0 ~ 2 ^ 32-1

Signed:-2 ^ 16-1 ~ 2 ^ 16-1

Float: Single-precision floating point, 32bit

Double: double Precision Floating Point type, 64bit

Long: long integer, 32bit

Char: bytes type, 8bit

Bool: boolean type, 0 and 1, 8bit true (true)/false (false)

Void: Empty type. If the function declaration does not return a value, use void

Sizeof: memory size occupied by computing variables or data types.

Add the undsigned keyword before the data type, and the variable is the data of the unsigned type.

Inum + = 2 and inum = inum + 2 share the same meaning

Inum-= 2 and inum = 2

Inum3 = inum ++ after the expression ++, first pay the value of the variable to the variable on the left, and then perform a + 1 operation on its own.

Inum2 = ++ inum indicates the front ++. First, perform a + 1 operation on the variable and pay the value after + 1 to the variable on the left.

Inum3 = inum -- after --, first pay the value of the variable to the variable on the left, and then perform a-1 operation on its own.

Inum2 = -- inum indicates the previous --, first perform a-1 operation on the variable, and then pay the value after-1 to the variable on the left.

Scanf: get basic data type data

Gets: Get a string

----------------

If (conditional expression)

{

Statement Block

}

Else if (conditional expression)

{

Statement Block

}

Else

{

Statement Block

}

----------------

Switch (number)

{

Case number:

Break;

  

Case number:

Break;

Default:

Break;

}

----------------

For (expression 1; expression 2; expression 3)

{

}

----------------

Wihile (conditional expression)

{

Loop body

}

----------------

Do

{

Loop body

} While (conditional expression)

----------------

Break exit Loop

The continue jumps to the start of the loop and re-executes it.

\ 0 indicates the end of the string, which is a non-printable character.

Char array [] = "hello"; the array size is not specified, which must be initialized.

Char array [10] = {0}; Initialization with no clear values is complete, which can only be initialized when defined.

**************************************** **********

Atoi string to integer

Atof String Conversion to single-precision floating point

Convert an atol string to a long integer

Before using the pointer, you must determine whether the pointer variable is null. If it is used up, you must release it if it is not null.

The pointer is the address of the variable.

Pointers are also of type. The pointer type specifies the Data Type address that the Pointer Points.

Int * PA = null; // defines an integer pointer. This variable can save the address of the plastic scalar.

Int a = 10;

PA = & a; // & get the address

Int B = * PA; // obtain the value in the address saved by PA.

 

Int iSize = 10;

Int * PInt = (int *) malloc (sizeof (init) * iSize); // equivalent to an integer array of 10 elements

Free (PInt); // releases the memory.

**************************************** *******

In C language, parameters are transmitted in two ways:

1) value transfer: it uploads a value to the function.

2) pointer passing: In a function, you can change the value in the address indicated by the pointer. After this value is called, this change remains valid.

Int & AA is a reference in C ++.

******************************

Storage media: disk files, tape files

By file encoding (Storage Format): text files, binary files

File Operations:

Open the file -- read and write the file -- close the file

Open a file: create a connection between a user program and a file and allocate a file buffer to the file.

Read/write: reads, writes, appends, and locates a file.

Close file: disconnect the file and program and release the File Buffer.

 

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.