C Programming language Reading notes

Source: Internet
Author: User
Tags float double mathematical functions

Preprocessor-". I compiler". "s assembler". O Linker-Executable file

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

The MATH.H header file contains declarations for various mathematical functions, all of which return a value of type double

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

Text flow: is a sequence of characters consisting of multiple lines of characters, each of which consists of 0 or more characters, and the end of the line is a newline character. The standard library is the model that each input and output stream adheres to.

1. In the C language, all the function parameters are ' The value passed, that is, the parameter value passed to the called function is stored in the temporary variable, rather than in the original variable, the value of the invocation is greater than the disadvantage, in the called function, the parameters can be considered as easy to initialize the local variables, so the additional use of fewer variables, so that the program can be more compact and concise. When an array name is used as a parameter, the value passed to the function is the position or address of the starting element of the array, it does not copy the array element itself, and in the called function, the value of the array element can be accessed or modified by an array subscript

The 2.c language provides four basic data types int char float double

Float 4 bytes, accurate to 6 decimal places

Double 8 bytes, accurate to 15 decimal places

Any number as long as the decimal point is a double type unless f is added,

Wide character type: Wchar_t=l ' a '; (in the standard header file <stddef.h; required include)

Boolean type:

_bool vaild=1;

bool Valid=true; (Requires #include<stdbool.h>)

3. Double quotation marks can be marked as a string, while single quotation marks only one character. Therefore, the contents of double quotation marks can not be directly compared, char cn[8]= "12345", cn1[8]= "1234"; To determine if a character is equal, you can use =, such as if (cn[1]== ' 2 '); To determine whether a string is equal, the function strcmp () is required;

4. From a technical point of view, a string constant is a character array. The internal representation of a string uses a null character, '% ', as the end of the string, so the number of physical storage units that store the strings is one more than the number of characters in double quotes. The standard library function strlen (s) can return the length of the string s, but the length does not include '

5. Enumeration constant enum names (enum tag) {name (enumerator) =val,name}, enumeration provides a convenient way to establish the association between a constant value and a name,

Scenario: You want a variable to store a set of Ken values, such as a variable that stores a value that represents the current month.

Each enumerator is specified with a unique name, and the compiler assigns an integer value of type int to each name.

An enumeration is an integer type because the specified enumerator corresponds to different integer values, which start from 0 by default, and each enumerator is 1 larger than its previous enumerator.

6. Type conversion: When several operand types of an operator are different, they need to be converted to some common type by some rules. Automatic conversion is the conversion of the ' narrower ' operand to the ' relatively wide ' operand. Show conversions to convert from a low type to a high type

7. To ensure the portability of the program, if you want to store non-character data in a variable of type char, it is best to develop signed and unsigned qualifiers

8. Even if the parameter of the calling function is char or float, we also declare the function argument to be of type int or double

8. In any expression, you can force a display type conversion (type name) expression with a unary operator that enforces the type conversion. Forcing type conversions

Just generates a value of N of the specified type, and the value of n itself does not change

9. The self-increment and decrement operators of prefixes and suffixes have the same effect when no specific value is required and only incremental variables are required

10. External variables: If two functions must share some data, and this two function does not call each other, in this case the most convenient way is to define these shared data as external variables, rather than as function parameters.

11. Name Scope: Refers to the part of the program that can use the name. For an automatic variable declared at the beginning of a function, its scope is the function that declares the variable, and there is no relationship between individual local variables declared in different functions that have the same name. The parameters of the function are the same, which can actually be thought of as a local variable

The scope of an external variable or function begins at the point where he is declared and ends at the end of the file to which it resides (to be compiled)

If you want to use the variable before the definition of an external variable, or if the definition of an external variable is not in the same source file as the variable, you must use the keyword extern in the corresponding variable declaration

The declaration of an external variable is strictly distinguished from the definition, which declares the attribute of the variable (mainly the type of the variable), and the definition will also cause the allocation of the memory.

In all source files of a source program, an external variable can be defined only once in a file, and other files can be accessed by an extern declaration. The length of the array must be specified in the definition of an external variable. However, the extern declaration does not necessarily specify the length of the array

The initialization of an external variable can only appear in its definition


The 12.static declaration qualifies external variables and functions to limit the scope of the objects declared later to the remainder of the compiled source file. By using static to qualify external objects, you can achieve the purpose of hiding external objects. External static declarations are typically used for variables or for functions. If a function is declared as a static type, the function cannot be accessed except for the file where the function declaration resides.

Static can also be used to declare internal variables. Unlike an automatic variable, it persists regardless of whether its function is called. The internal variable of the static type is a variable that can only be used in a particular function but occupies the storage space

13. Register variable Register declaration tells the compiler that the variable it declares is used more frequently in the program, and its idea is to place the Redister variable in the register of the machine, which makes the program smaller and faster to execute. But the compiler can ignore this item

The Register declaration applies only to automatic variables and formal parameters of functions P68

14. Initialization: In the case of no explicit initialization, both the external and static variables are initialized to 0, and the initial values of the automatic and register variables are undefined (i.e., the initial value is useless information)

When you define a scalar variable, you can initialize the variable with a good and an expression immediately after the name of the tag.

For external variables and static variables, the initialization expression must be a constant expression and be initialized only once (conceptually, before the program starts executing)

For automatic variables and register variables, it is initialized each time a function or block is entered.

15. Preprocessor: Conceptually, a preprocessor is the first step in the compilation process

#include used to include the contents of the specified file into the current file during compilation

Lines like # include "file name" or #include < file name > will be replaced with the contents of the file specified by the filename. If the file name is enclosed in quotation marks, it is found in the location where the source file is located, if the file is not found in that location, or if the file name is enclosed in angle brackets <>, the rule is relative to the specific implementation. The included file itself can also contain a # include directive

#define NAME Substitution text This is a simple macro substitution where all occurrences of the name Mark will be replaced with the replacement text. #define指令定义的名字的作用域从其定义点开始, end at the end of the compiled source file. The substitution is only for tokens, and the string enclosed in quotation marks does not work, and the replacement text can be arbitrary.

A macro definition can also take a parameter disk p72, which looks like a function call, but the macro call is to insert the replacement text directly into the code. Each occurrence of a formal parameter is replaced with a corresponding actual parameter (with a certain flaw, when the argument expression has side effects, and the parentheses are not used properly)

If the processing of parameters of various types is consistent, you can apply the same macro definition to any data type without having to define different functions for different data types

Conditions include: Using conditional statements to control the preprocessing itself, the value of this conditional statement is evaluated during preprocessing, which provides a means to selectively include different code in the compilation process based on the calculated condition value

* * Pointers and Arrays

Pointer: A set of storage units that hold an address

The unary operator & the address of an object, which can only be applied to objects in memory, that is, variables and array elements, which cannot be applied to variables of expression constants or register types

The unary operator * is an indirection or indirect reference operator. When acting on a pointer, the object to which the pointer points is accessed. Declaring pointer variables

Each pointer must point to a specific data type (a pointer of type void can hold any type of pointer, but cannot indirectly refer to itself)

Pointer parameters enable the called function to access and modify the value of the object in the key function

Array: The value of a variable or expression of the P79 array type is the address of the No. 0 element of the array, and the array name represents the address of the first element of the array.

An expression implemented by an array and subscript can be implemented equivalently by pointers and offsets

Array name A pointer has a difference, the pointer is a variable, the array name is not a variable (pointers pa=a and pa++ are both legal, array names A=pa and a++ are illegal)

When an array name is passed to a function, the address of the first element of the array is actually passed

In the function definition, the formal parameter char s[] and char *s are equivalent. The latter is more intuitive than the former that the parameter is a pointer

The array name is passed to the function, and the function can be judged by the array or by the pointer to handle

You can also pass a pointer to the starting position of the subarray to the function so that part of the array is passed to the function p81

Address arithmetic operations:

Pointers and integers cannot be converted to each other, but 0 is the only exception: constant 0 can be assigned to pointers, pointers can also be compared to constant 0, the usual symbolic constants in the program are null instead of constant 0, so that it is easy to clearly explain that the constant 0 is a special value of the pointer

Pointer arithmetic: comparison (pointer p and Q point to the member of the same array to make sense), and integer plus minus

Pointer operations are consistent, and all pointer tuples automatically take into account the length of the object it points to

P85

C Programming language Reading notes

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.