C---Knowledge Point summary 1

Source: Internet
Author: User
Tags types of functions

Variable:

1. Definition of variables

Variable type variable name;

int score;

2. Assigning values to variables

score = 100;

Score = A;

Score = b = 100;

3. Output of variables

int a = 200;

printf ("%i", a);

Common format characters:

1>%d\%i Integer (int)

2>%f decimal (float, double)

3>%c character (char)

Variable Use NOTE:

1. Scope of variables

Start with the line of code that defines the variable until the end of the code block where it resides

2. The role of code blocks

Timely recycling of variables that are no longer used in order to improve performance

Swap variables:

A = 10

b = 11

After Exchange

A-11

B-10

1. Use of third-party variables (work, mastery)

int temp = A;

A = b;

b = temp;

2. Do not use third-party variables (interviews, impressions)

A = b-a;

b = b-a;

A = B + A;

What steps does the C program require from development to operation?

1> writing. C Source Files

2> compile. C source file for. O Destination file

3> link. o The target file is an executable file

4> running an executable file

Expand what files are called. C,. O,. Out, respectively? At what stage of the C program development?

1>. c is a C language source file that is created when writing code

2>. O is the target file, which is generated when the compilation is successful

3>. Out is an executable file that is generated when the link succeeds

Variable Memory:

1. Memory addressing from large to small, priority allocating memory addresses larger bytes to the variable

2. The more the variable is defined, the greater the memory address

3. Get the address of the variable:& variable name

4. Output Address:%p

5. A variable must be advanced to initialize the line in order to use

The scanf function uses:

1. Define a variable to hold the integer entered by the user

The 2.SCANF function accepts only the address of the variable

The 3.SCANF function is a blocking function that waits for the user to enter

4. When user input is complete, the value entered by the user is assigned to the number variable

5. Function call Complete

1. Enter characters

2. Enter multiple values at once and separate them with some symbols

3. If the scanf parameter is separated by a space, the actual input can be delimited by a space, tab, carriage return

Cannot write \ n in 4.scanf

Algorithm operation:

1. Take the remainder operation (modulo operation)

2.%, both sides are integers.

The positive and negative results of the 3.% are only related to the value on the left side.

4. Automatic type conversion (Double->int)

int a = 10.8;

Coercion type conversion (Double->int)

int b = (int) 10.5;

printf ("%d\n", a);

Automatic type lift (int->double)

Double c = 10.6 + 6;

5.sizeof function, sizeof (ten), sizeof, sizeof (10.9), sizeof 10.9,sizeof (int), sizeof (char)

6. Relational operations

The condition is set to return 1, really

If the condition is not established, return 0, False

7. Logic and Conditions 1 && conditions 2

Logic or Condition 1 | | Condition 2

The logic is not! The condition returns 0 if the condition is true, and returns 1 if the condition is not established.

8. Three mesh operator conditions? Value 1: Value 2 condition True, take value 1; condition false, take value 2

9. When comparing the size, the constant value is left, the variable is placed to the right, which prevents the write error, especially if the write comparison is equal to the situation

(Write if (a==0), may be written as if (a=0), so write wrong may appear warning, not error,

But if the if (0=a), less write will prompt the wrong, should be written if (0==a))

10. Note The assignment operator, do not write two =

Do not write after 11.if statement;

12. If you want to define a new variable in the statement after the IF, you must use the curly braces {}

13.if and switch

if (condition)

{

}

Switch (value)

{

Case value 1:

Statement 1;

Break

Case Value 2:

Statement 2;

Break

Default:

Statement 3;

Break

}

1.break: Exit the entire switch statement

2. If there is no break after the case, the statement in all subsequent statements is executed until a break is encountered

3. If you want to define a new variable after the case, you must enclose it in curly braces {}

4.if and switch similarities and differences

1> If statement can be done, switch does not necessarily complete

int a = 10;

if (a>100)

{

}

2> in some cases, if statements and switch statements can be interchanged

3> switch can complete the function, if statement can be completed

SCANF Note:

scanf must pass in the address of the variable instead of passing in the value of the variable directly

Do not include \n,\n in scanf have special meaning to scanf

Note Item:

10 is a constant and cannot be operated with + +

Because 10++ equals 10 = 10 + 1

int a = 10++;

% must be an integer on both sides

If and while

if (condition)

{

}

while (condition)

{

Loop body

}

Operating principle

1. If the initial condition is not established, the loop body will never be executed

2. If the condition is set up, a loop body is executed, the execution is completed, and the condition is determined again.

Break

Directly ends the entire while loop

Continue

End the current loop body and go to the next loop body execution

1. First identify the actions that need to be performed repeatedly

2. Re-determination of constraints

3. The simplest dead loop while (1);

While and Do-while

while (condition)

{

}

do {

} while (condition);

The difference between while and do-while

1. In many cases, while and do are interchangeable

2.while Features: If the initial conditions are not true, the loop body will never be executed

Do While features: at least one cycle body is executed regardless of whether the first condition is true

3. It is best to use while

For loop:

for (statement 1; condition; statement 2)

{

Loop body

}

Statement 1: Initializing statements

Statement 2: Increment statement (statement executed after execution of the loop body)

1.for executes statement 1 at the beginning (the entire for loop executes only once)

2. Determine whether the condition is established, if the condition is established, will be executed once the loop body, then will execute the statement 2, again determine whether the condition is established

Don't write semicolons behind for ()

for (int i=0; i<5; i++);

{

printf ("haha \ n");

}*/

/* ERROR: Scope of variable A is ambiguous

If you want to define a new variable in the loop body, you must enclose it in curly braces {}

The simplest use of a for loop to achieve a dead loop for (;;);

Break and Continue:

Break

1. Use Cases

1> Switch statement: Exit the entire switch statement

2> loop structure: Exits the entire loop statement

* While

* Do While

* FOR

2. Attention points

Valid only for the nearest loop structure

Continue

1. Use Cases

Loop structure: End the current cycle body, enter the next cycle body

* While

* Do While

* FOR

2. Attention points

Valid only for the nearest loop structure

Function:

1. When to define a function: Add a common new feature

2. Function definition Format

return value type function name (formal parameter list)

{

function body

}

3. Defining a function requires something clear

1> a meaningful function name

2> determining the number of formal parameters of a function

3> determining the return value of a function

Parameter Note points

1. Formal parameters: A parameter that is followed by a function name when defining a function, for short, a formal parameter

2. Actual parameters: Call the function of the specific data passed in, referred to as an argument

3. The number of arguments must be equal to the number of formal parameters

4. Variables within the function body that cannot be defined as parameters

5. If the base data type is a function parameter, it is purely a value pass, modifying the value of a function's internal parameter without affecting the value of the outer argument

6. A function can have no formal parameters, or can have an infinite number of parameters

Formal parameters, referred to as formal parameter

The function of return:

1> Exit Function

2> returns a specific value to the function caller

Return value Note point

1> void represents no return value

2> If the return value type is not explicitly stated, the default is to return the int type

3> even if the return value type is explicitly declared, no value can be returned

By default, the C language does not allow the same names as two functions

function Status Note:

1. By default, the name of a function is not allowed

2. Functions cannot be nested defined

3. Functions cannot be defined repeatedly, but can be declared repeatedly

4. If there is a function declaration, there is no definition of the function

1> compilation can be passed, because the compiler will only detect the syntax is not reasonable, and will not detect the function has no definition

2> link error, because the link will detect whether the function is defined

Include

1> function: Copy all contents of the right file to the location of # include

2> custom files with "", the system comes with the file <>

3> #include <stdio.h> Purpose: Copy the declaration of the printf function

\ n is an escape character

\ t Tab key

\ "A double quote

The character count of the string constants returned by the printf function, not the number of words

1 kanji (s) of 3 characters

1. function definition put. c file, function declaration put. h file

2. If you want to use a function defined in a. c file, you only need to include the. h file that corresponds to the. c file.

The role of 3..h files: copied by others. You do not need to pipe. h files when compiling links.

4.cc XX.O XXX.O to link multiple target files together

CC XX.C XXX.C compiling and linking multiple source files

Void means there is no return value, so you should not return an integer omitting return is also available

The return value is of type int, so return should follow an integer return 0 this 0 is just a random write, what value to return, should be based on business logic

Functions cannot be nested defined

Functions with the same name are not allowed unless they have different number of parameters and types of functions

Partial Summary:

I. CHOICE of structure

1.if

1> structure

if (condition) {

} else if (condition 2) {

} else if (condition 3) {

} else {

}

2> Features

* At the same time, only one curly brace code will be executed

2.switch

1> structure

Switch (value)

{

Case value 1:

Break

Case Value 2:

Break

Case Value 3:

Break

Default

Break

}

2> Features

1> by default, only one of the code following the case is executed

2> If there is no break behind a case, and if the case is true, then the statements in all of the following are executed sequentially until a break is encountered

3> if you want to define a new variable after the case, you must enclose it in curly braces {}

Second, the cycle structure

1.while

1> Features: If the initial condition is not established, the loop body will never be executed

2.do while

1> features: At least one cycle body will be executed regardless of whether the condition is established

3.for

4. Select

1> general preference for use for loops

2> and then consider the while.

3> finally consider the Do and

C---Knowledge Point summary 1

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.