1. Shaping upgrades and ordinary arithmetic conversions:
Char,short int or bit segments, including their signed and unsigned type, as well as enumeration types, can be used in an expression of the required int or Unsignede int. If int can fully represent all the values of the source type, then the value of the source type is converted to type int, otherwise it is converted to an unsigned type, which is called a cosmetic upgrade.
For other types of conversions, if there are two operands: the conversion relationship is as follows:
Long double------others type---------------> Long double
Double-------others type--------------> Double
float------Others type--------------> float
Otherwise, a cosmetic upgrade
unsigned long int---------others type-----------> unsigned long int
long int-----------------------unsigned int if the long shape can fully represent all the values of unsigned shaping, then unsigned shaping is converted to a long integer, otherwise all of them are converted to unsigned long shaping.
Recommendation: Unsigned numbers are used when bit and binary masks are used, and it is not recommended to use such unsigned types in other cases.
Null means nothing to point (null pointer), NUL means to end an ASCII string.
Some problems with the switch statement;
The default can be free to appear in any position, and if there is no case to match it, then the switch statement does nothing, C does not check the situation, but Pascal's language is checked.
The order of each case and default can be arbitrary, and it is customary to put default at the end.
In cases where there is no break after each case, it is called "fall through", which requires special comments.
Understand the precedence rules of the C language:
A. The declaration begins with its name and is then read in order of precedence.
B. Priority from high to bottom is:
1. The part of the declaration that is enclosed in parentheses.
2. Suffix operator:
the brackets () indicate that this is an array, and the square brackets "" means that this is an array.
3. Prefix operator: * Asterisks indicate "point to ...". 's pointer. "
C. If the const or volatile keyword is immediately behind the type specifier, it acts on the type specifier. In other cases, it acts on the pointer to the left of the asterisk.
Note the difference between typedef and define
typedef cannot be combined to define, define only works on the first parameter.
The difference between a declaration and a definition:
Definition: Appears only in one place, determines the type of object and allocates memory for creating new objects, such as int a[100]; Corresponds to a special declaration and allocates memory for the object.
Declaration: can appear multiple times, describing the type of object used to refer to objects defined elsewhere (extern int A; Description is not self, but rather describes objects elsewhere.
Difference between left and right values:
x = y;
X is the Lvalue essence represents an address, and the right value y here essentially represents a content.
The difference between an array reference and a pointer reference:
Char a[9] = "ABCDEFGH";
c = A[i];
First the compiler takes the address of a, the first address of the array element, and then takes the value of I and the first address to add
Then take out the contents of the address.
char * p;
c = *p;
First, the compiler symbol table has a symbol p, assuming its address is 5000,
The compiler then takes out the contents of address 5000, which is the first address of the array, and then extracts the contents of the address.
When defined as a pointer, but referenced in an array, this time the value method is a blend of the top two ways.
Now summarized as follows:
1. Obtain the address of P in the symbol table and extract the pointer stored here.
2. Add the offset represented by the subscript to the value of the pointer, resulting in an address.
3. Access the above address to get the character.
When you define a pointer, the compiler does not allocate space for the object that the pointer points to, it simply allocates space for the pointer itself, unless it is initialized with a string constant assigned to the pointer at the same time as defined. Where string constants are stored in only the text segments that are allowed to be read, to prevent modification.
Re-explore arrays and pointers:
Let's start with the declaration:
The declaration itself can be further divided into 3 different situations:
1. Declaration of an external array.
2. Definition of the array.
3. Declaration of function parameters.
All array names that function as arguments can always be converted to pointers by the compiler.
(Be careful to define an array in one file, which is declared as a pointer in another file)
So: the declaration of an array is an array, the declaration of a pointer is a pointer, for the compiler, an array is an address, a pointer is the address of an address.
In an expression, pointers and arrays are interchangeable, because their final form is pointers.
But why the C language takes an array parameter as a pointer is just for the sake of efficiency.
There is no way to pass the array itself to a function, because it is always automatically converted to pointers to arrays, so the sizeof operator can no longer help us to find the length of the array, which can only be used in the local stack.
Right now:
Summary of commutative arrays and pointers:
1. Think A[1] is always rewritten by the compiler to * (a+1) This situation.
2. The pointer is always a pointer it can never be changed into an array, but it can be accessed in the same way as the subscript, or it can be passed as a parameter.
3. In a particular context, that is, its argument as a function (and only in this case) an array declaration can be seen as a pointer. An array that is a function parameter is always modified by the compiler to a pointer to the first element of the array.
4. Therefore, when you define an array as a function parameter, you can arbitrarily choose whether to define the pointer or define the array, after all the compiler gets just a pointer.
5. In other cases, the declaration and definition must match.
Method of passing an array to a function:
1. Add an additional parameter that represents the number of elements.
2. At the end of the array, add a special value that indicates that it is the end of the array because the C language does not check the end.
The last question about pointers and arrays:
such as and exchange of two values:
<span style= "FONT-SIZE:24PX;" >temp = a ; a = b ; b = temp; a ^= b; b ^= A; a ^= b; a = A+b;b = A-b;a = a-b;</span>
In fact, these exchanges have their advantages and disadvantages:
The first method is to use an intermediate variable obviously,
The second method: the condition 1.a and B must be met with atomic operations and no hardware failure, insufficient space, or a mathematical operation failure.
The third method: there is the possibility of crossing the border.
In-Memory "fishy":
C language: First compile and then connect.
B Language: First connected and then compiled.
Paragraph
In Unix, a segment represents a content block related to a binary file.
In Inter X86, a segment represents a design result. Are some areas of size 64K.
The General C program has three basic segments: BSS segment, text segment, data segment. See the previous blog post ' C and Ram ' for details.
Stack segment:
Contains a single data structure, which is the stack.
It contains a global pointer to the top of the stack that the SP uses to hint.
Role:
1. The stack provides storage space for local variables declared inside the function.
2. When making a function call, the stack stores some maintenance information about this, and another more common name is the process activity record.
3. The stack can also be used as a temporary storage area.
The stack is growing downward,
Process Activity record:
In short, this thing is a C language that comes with a function to monitor the functions being called.
Contains:
A local variable, a parameter, a static link, a pointer to a previous struct, and a return address.
This also grows downward in memory. that is, it grows toward the low address direction.
"C Expert Programming" learning Note 1