Embedded C-language beginner programming with the Tang notes

Source: Internet
Author: User
Tags square root uppercase letter

Review) The function of the pointer: the address of the store variable, the indirect operation variable, can be arbitrarily pointed.

A function can abstract a function that is relatively independent, making it an independent entity in the program. Can be reused multiple times in the same program or other program.

The core focus is reusing code.

Meaning: is the basic unit for process programming.

A function completes a basic function.

Two. Function type:

1. Built-in functions: The language is provided by the word system, the user does not need to define, and does not have to make type description in the program; simply include the header file with the function definition before the program;

Note: If you have a header file, you will still not be able to use the link-lm (the pen question in the interview is generally not used by default).

Common built-in functions: Double sqrt (double x) calculates the square root of X

Double pow (double x, double y) calculates the y power of X

Double ceil (double x) to find the smallest integer not less than x, and to display in double form

Double floor (double x) is not greater than the largest integer of x and is displayed in double form

int toupper (int x) if x is lowercase, the corresponding uppercase letter is returned

int tolower (int x) if x is uppercase, the corresponding lowercase letter is returned

int rand (void) produces a random number

2. Custom function: A Programmer's self-written function

return value type function Name argument list function body

The result of the calculation in the function body can be returned to the outside using a return to external use externally can be passed through the parameter list to the function body value.


3. Function declaration

Returns a value type function name parameter list;

Use: When a function is defined after main (), if the function is called in Main (), then the declaration of the function must be added before main ().

4. Invocation of functions

4-1 nested call void Fun_b () {xxxxx;}

void Fun_a () {fun_b (); xxxxx;}

void Main () {fun_a (); xxxxx;}

4-2 recursive invocation (function calls itself)

void Fun_a ()

{

xxxxx

Fun_a ();

xxxxx

}

Characteristics of Recursive functions: (1) Conditions of recursion end (2) recursive formula

Recursive calls generally have if_else

5! =5*4!

1! =1

Pros: Simple and straightforward code

Cons: More resources are consumed during execution

Input:5

Main ()

Fact (5)

A*=fact (4)

A*=fact (3)

A*=fact (2)

A*=fact (1)

return 1;

Hazard: A segment error can occur when the number of recursive layers is greater. Because the resources will be exhausted.

What is the value on the nth bit of the non-Bernard number?

1 1 2 3 5 8 13 31 34 ...

if (1==num| | 2==num)

return 1;

Else

Return Fun (num-1) +fun (num-2)

5. Scope of the variable (scope)

5-1 scope: The effective area of certain things

Local variable: A variable in a function or statement block (called a statement block in curly braces})

Example: 1.int main ()

{

int a;//local variable

}

2.

int fun (int b)//local variable B

{

}

Scope: Variable definition------at the end of the function

Global variables: Variables outside the function

Scope: can be used in any function

Think: What happens if a local variable in a function has the same name as a global variable?

Answer: The local variable overrides the scope of the global variable.


6. The storage type of the variable: static and dynamic.

Auto Automatic variable

int main ()

{

Auto int a;//is equivalent to int A;

}

Register register variable (fast operation)

regitster int i;

for (I=0;i<10000000000;++i)

{

xxxxxxxx

}

Static statically variable

Scope

Local variable definition----return definition---------return

Static local variable----return definition---------program end



Embedded C-language beginner programming with the Tang notes

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.