C/C ++ pointer application (Tutorial)

Source: Internet
Author: User
Detailed explanation of C/C ++ pointer application (retention learning)
To understand pointers, there may be more or less complex types. So I will first introduce how to fully understand a complex type. To understand complex types, there will be many operators in a type, they also have priorities, just like normal expressions. Their priorities are the same as their operational priorities. So I have summarized their principles:
Starting from the variable name, it is analyzed step by step based on the combination of operator priorities.
Next, let's start from a simple type and analyze it slowly:
Int P; // This is a common integer variable.
Int * P; // start with P and combine with * First. Therefore, P is a pointer and then combined with Int, indicates that the Pointer Points to the int type of content. so P is a pointer to return integer data.
Int P [3]; // start with P and combine it with [] First, indicating that P is an array and then combined with int, indicating that the elements in the array are integer, therefore, P is an array composed of integer data.
Int * P [3]; // starting from P, it is first combined with []. Because the priority is higher than *, P is an array and then combined, it means that the elements in the array are pointer types, and then combined with int, it means that the type of the content pointed to by the pointer is integer, so P is an array composed of pointers that return integer data.
INT (* P) [3]; // starts from P, and is first combined with *, indicating that p is a pointer.
// Then combine with [] (and "()" This step can be ignored, just
// Changed the priority), indicating that the pointer points to
// Array, and then combined with int, the elements in the array are
// Integer. So P is a number that points to an integer.
// Group pointer
Int ** P; // start with P and first combine with *. P is a pointer.
// Combined with *, it indicates that the element pointed to by the pointer is a pointer.
// Combined with int, it indicates that the element pointed to by the pointer is an integer.
// Type data. The second-level pointers and more advanced pointers are rarely used.
// In complex types, we will
// Multi-level pointers are not taken into account. A maximum of first-level pointers are considered.
Int P (INT); // starts from P. It is first combined with (), indicating that p is a function and then enters
// (), Indicating that the function has an integer Variable Parameter
// Then combine it with the int value, indicating that the return value of the function is
// An integer
INT (* p) (INT); // starting from P, it is first combined with the pointer, indicating that p is a pointer, and then
// () Indicates that the pointer points to a function and
// Int indicates that the function has an int parameter and
// Int indicates that the return type of the function is integer, so P indicates
// Returns the pointer to a function with an integer parameter and an integer type.
Int * (* P (INT) [3]; // It can be skipped first. It is too complicated to read this type.
// Starting from P, it is first combined with (), indicating that p is a function, and then
// In (), combined with int indicates that the function has an integer variable.
// The parameter, and then combine it with the external *, indicating that the function returns
// A pointer, then to the outermost layer, first combined with [], description
// The returned Pointer Points to an array and then combines it *,
// The element in the clear array is a pointer and then combined with int, which indicates
// The content pointed to by the needle is integer data, so P is a parameter
// Round the data and return an array pointing to an integer pointer variable
// Pointer variable function.
It is almost the same here, and we have so many tasks. We have understood these types and other
The type is also a small dish for us, but we generally do not use too complex types, that will
This greatly reduces the readability of the program. Please use it with caution. The above several types are enough for us to use.
1. Detailed pointer
A pointer is a special variable. The value stored in it is interpreted as an address in the memory.
To understand a pointer, we need to understand four aspects of the pointer: pointer type, pointer pointing
Type, pointer value, memory zone pointed to by pointer, memory zone occupied by pointer. Let
We describe them separately.
First, declare several pointers for example:
Example 1:
(1) int * PTR;
(2) char * PTR;
(3) int ** PTR;
(4) int (* PTR) [3];
(5) int * (* PTR) [4];
1. pointer type
From the perspective of syntax, you only need to remove the pointer name in the pointer declaration statement, and the remaining parts
This is the pointer type. This is the type of the pointer. Let's take a look
Pointer types:
(1) int * PTR; // the pointer type is int *
(2) char * PTR; // the pointer type is char *
(3) int ** PTR; // the pointer type is int **
(4) int (* PTR) [3]; // the pointer type is int (*) [3]
(5) int * (* PTR) [4]; // the pointer type is int * (*) [4]
How is it? Is it easy to find the pointer type?
2. Type pointed to by pointer
When you access the memory area pointed to by the pointer, the type pointed to by the pointer determines
The compiler treats the content in the memory area as something.
In terms of syntax, you only need to declare the pointer name and the pointer sound on the left of the name in the pointer declaration statement.
The identifier * is removed, and the rest is the type pointed to by the pointer. For example:
(1) int * PTR; // The Pointer Points to an int type.
(2) char * PTR; // The Pointer Points to a char type.
(3) int ** PTR; // The type pointed to by the pointer is int *
(4) int (* PTR) [3]; // The type pointed to by the pointer is int () [3]
(5) int * (* PTR) [4]; // The type pointed to by the pointer is int * () [4]
In pointer arithmetic operations, the type pointed to by the pointer has a great effect.
The pointer type (the pointer type) and the pointer type are two concepts. When you
When you are getting familiar with C, you will find that the concept of "type" mixed with pointers is divided
The concepts of "pointer type" and "pointer type" are one of the key points to be proficient in pointers.
I read a lot of books and found that some poorly written books bring together the two concepts of pointers,
As a result, the conflicts between books become increasingly confusing.
3. pointer value ---- or the memory zone or address pointed to by the pointer
The pointer value is the value stored by the pointer itself. This value will be treated as an address by the compiler, and
It is not a common value. In a 32-bit program, the value of all types of pointers is a 32-bit
Integer because the memory address in the 32-bit program is all 32-bit long. The memory area to which the Pointer Points
Starting from the memory address represented by the pointer value, the length is SI zeof (class pointed to by the pointer
Type. Later, we will say that the value of a pointer is XX, which is equivalent
Directed to a memory area headed by xx; we say a pointer points to a memory area,
It is equivalent to saying that the pointer value is the first address of the memory area.
The memory zone pointed to by the pointer and the type pointed to by the pointer are two completely different concepts. In Example
1. the type to which the Pointer Points already exists, but since the pointer has not been initialized, it points
Memory zone does not exist, or is meaningless.
In the future, every time you encounter a pointer, you should ask: What is the type of this pointer? Pointer
What is the type? Where does this pointer point? (Important)
4. Memory occupied by pointers
How much memory does the pointer occupy? You just need to test it using the sizeof function (pointer type ).
You will know. On a 32-bit platform, the pointer occupies 4 bytes.
The memory occupied by pointers is used to determine a pointer expression (which will be explained later ).
It is useful when no is the left value.
2. arithmetic operations on pointers
The pointer can be added or subtracted from an integer. The meaning of this operation of pointer and addition and subtraction of common values
The meaning of the operation is different, in units. For example:
Example 2:
Char A [20];
Int * PTR = (int *) A; // The forced type conversion does not change the type of.
PTR ++;
In the preceding example, the pointer PTR is of the int type * and it points to the int type. It is initialized.
To point to integer variable. In the next 3rd sentences, the pointer PTR is added with 1, and the compiler is like this.
Processing: It adds the value of the pointer PTR to sizeof (INT). In a 32-bit program
4, because in 32-bit programs, int occupies 4 bytes. Because the address is in bytes,
Therefore, the address pointed to by PTR is increased by four bytes from the address of the original variable A to the direction of the high address.
Since the length of the char type is one byte, the PTR originally points to the 0th of array.
The four bytes starting from the unit, which points to the four bytes starting from Unit 4th in array.
We can use a pointer and a loop to traverse an array. For example:
Example 3:
Int array [20] = {0 };
Int * PTR = array;
For (I = 0; I <20; I ++)
{
(* PTR) ++;
PTR ++;
}
In this example, the value of each unit in the integer array is added to 1. Since every loop has a pointer PTR
Add 1 unit, so each loop can access the next unit of the array.
Let's look at the example:
Example 4:
Char A [20] = "you_are_a_girl ";
Int * PTR = (int *);
PTR + = 5;
In this example, PTR is added with 5, and the compiler processes it like this:
If the value is 5 x sizeof (INT), 5x4 = 20 is added to the 32-bit program. Due to address
The Unit is byte, so the current PTR points to the address compared to the address pointed by the PTR after the addition of 5
For example, 20 bytes are moved to the high address. In this example, the PTR before 5 is not added.
To the four bytes starting from Unit 0th of array A, after adding 5, PTR has pointed to
It is out of valid range. Although this situation may cause problems in applications, it is possible in terms of syntax.
This also reflects the flexibility of pointers.
If in the above example, PTR is subtracted from 5, the processing process is similar, except that the PTR
If the value is subtracted by five times sizeof (INT), the new PTR points to an address that is greater than the original PTR points
The address is moved 20 bytes to the lower address.
Here is another example: (A misunderstanding)
Example 5:
# Include <stdio. h>
Int main ()
{
Char A [20] = "you_are_a_girl ";
Char * P =;
Char ** PTR = & P;
// Printf ("P = % d \ n", P );
// Printf ("PTR = % d \ n", PTR );
// Printf ("* PTR = % d \ n", * PTR );
Printf ("** PTR = % C \ n", ** PTR );
PTR ++;
// Printf ("PTR = % d \ n", PTR );
// Printf ("* PTR = % d \ n", * PTR );
Printf ("** PTR = % C \ n", ** PTR );
}
Misunderstanding 1. Output answer: Y and O
Misunderstanding: PTR is a char second-level pointer. When executing PTR ++;, it will add a pointer
Sizeof (char), so output of the above results, this may be the result of a small number of people.
Misunderstanding 2. Output answer: Y and
Misunderstanding: PTR points to a char * type. When PTR ++ is executed, a pointer is added.
Sizeof (char *) (some people may think that this value is 1, then you will get a wrong answer
Case, this value should be 4, refer to the previous content), that is, & P + 4; then the value calculation is not performed
Does it point to the fifth element in the array? The output result is not the Fifth Element in the array.
Is it plain? The answer is no.
Positive solution: the PTR type is Char **, pointing to a char * type, pointing
The address is the address of P (& P). When PTR ++ is executed, a sizeof (char
*), That is, where does * (& P + 4) point to? Ask God, or he will tell you
Where? Therefore, the final output is a random value, which may be an invalid operation.
Summary:
After a pointer ptrold is added (subtracted) by an integer N, the result is a new pointer ptrnew,
Ptrnew and ptrold are of the same type.
The types to be pointed to are also the same. The value of ptrnew will increase (decrease) n multiplication than the value of ptrold.
Sizeof (the type that ptrold points to) bytes. That is to say, ptrnew points to the memory
The area moves n multiplication to the high (low) Address direction than the memory area pointed to by ptrold.
Sizeof (the type that ptrold points to) bytes.
Add or subtract pointer and pointer:
The two pointers cannot be added. This operation is invalid because the obtained
The result points to an unknown place and is meaningless. Two pointers can be subtracted.
Operation, but must be of the same type. It is generally used in arrays.
3. Operators & and *
Here & is the address operator, and * is the indirect operator.
& The operation result of A is a pointer. the pointer type is a value of type *.
The pointer to the address is the address of.
* P's computation results are varied. In short, * the result of P is what P points,
This item has these features: its type is the type pointed to by P, and the address it occupies is P
Address.
Example 6:
Int A = 12; int B; int * P; int ** PTR;
P = & A; // The result of & A is a pointer, whose type is int * and whose type is
// Int, pointing to the address of.
* P = 24; // * P result. Here its type is int, and its occupied address is
// The address pointed to by P. Obviously, * P is variable.
PTR = & P; // The result of & P is a pointer. the pointer type is p type *,
// Here it is int **. The Pointer Points to the p type.
// The value is int *. The Pointer Points to the address of P itself.
* PTR = & B; // * PTR is a pointer, and the result of & B is also a pointer. The two pointers
// The type is the same as the type pointed to, so use & B to assign * PTR
// The value is no problem.
** PTR = 34; // * the result of PTR is what PTR points to. Here it is a pointer,
// Perform another operation on the pointer *. The result is an int type variable.
4. pointer expression
If the result of an expression is a pointer, the expression is called a pointer table.
Below are some examples of pointer expressions:
Example 7:
Int A, B;
Int array [10];
Int * pA;
Pa = & A; // & A is a pointer expression.
Int ** PTR = & PA; // & PA is also a pointer expression.
* PTR = & B; // * PTR and & B are pointer expressions.
Pa = array;
Pa ++; // This is also a pointer expression.
Example 8:
Char * arr [20];
Char ** Parr = arr; // If arr is regarded as a pointer, arr is also a pointer expression.
Char * STR;
STR = * Parr; // * Parr is a pointer expression.
STR = * (Parr + 1); // * (Parr + 1) is a pointer expression.
STR = * (Parr + 2); // * (Parr + 2) is a pointer expression.
Since the result of a pointer expression is a pointer, the pointer expression also has a pointer
There are four elements: pointer type, and memory zone,
Memory occupied by the pointer itself.
Well, when the result pointer of a pointer expression has clearly occupied the pointer itself
The pointer expression is a left value, otherwise it is not a left value.
In Example 7, & A is not a left value because it does not occupy clear memory. * PTR is
A left value, because * the PTR pointer occupies the memory. In fact, * PTR is the pointer Pa,
Since PA already has its own location in the memory, * PTR certainly has its own bit
.
5. Relationship between arrays and pointers
The array name can be regarded as a pointer. See the following example:
Example 9:
Intarray [10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, value;
Value = array [0]; // It can also be written as: value = * array;
Value = array [3]; // It can also be written as: value = * (array + 3 );
Value = array [4]; // It can also be written as: value = * (array + 4 );
In the preceding example, the array name array represents the array, and the type is int [10 ].
If we think of array as a pointer, it points to the 0th units of the array, whose type is int *,
The Type pointed to is the type of the array unit, that is, Int. Therefore, * If array is equal to 0, it is not at all.
Strange. Similarly, array + 3 is a pointer to the array's 3rd units, so
* (Array + 3) equals 3. Others.
Example 10:
Char * STR [3] = {
"Hello, thisisasample! ",
"Hi, Goodmorning .",
"Helloworld"
};
Chars [80];
Strcpy (S, STR [0]); // It can also be written as strcpy (S, * Str );
Strcpy (S, STR [1]); // It can also be written as strcpy (S, * (STR + 1 ));
Strcpy (S, STR [2]); // It can also be written as strcpy (S, * (STR + 2 ));
In the preceding example, STR is an array of three elements, and each element of the array is a pointer,
Each Pointer Points to a string. If the pointer array name STR is treated as a pointer, it
Point to unit 0th of the array. Its type is Char **, and it points to char *.
* STR is also a pointer. Its type is char * and it points to Char.
The address is the string "Hello, thisasample! The address of the first character, that is
'H' address. Note: The string is equivalent to an array, which is stored as an array in the memory.
Only the string is an array constant, the content cannot be changed, and can only be the right value.
As a pointer, it is a constant pointer and a pointer constant.
STR + 1 is also a pointer pointing to unit 1st of the array. Its type is Char **,
It points to a char * type *.
* (STR + 1) is also a pointer. Its type is char * and it points to Char,
It points to the first character 'h' of "Hi, Goodmorning'
The following is a summary of the array name (which is also stored in the array:
If an array type array [N] is declared, the array name array has two meanings:
First, it represents the entire array, and its type is type [N]; second, it is a constant
Pointer. the pointer type is type *. The Pointer Points to type, that is, an array.
The type of the Unit. The memory area to which the Pointer Points is the unit 0th of the array.
There is a separate memory zone. Note that it is different from the memory zone occupied by the array unit 0th. The
The pointer value cannot be modified, that is, the expression similar to array ++ is incorrect.
In different expressions, array names can play different roles.
In the expression sizeof (array), the array name array represents the array itself.
The sizeof function measures the size of the entire array.
In the expression * array, array acts as a pointer, so the result of this expression is
The value of unit 0th in the array. Sizeof (* array) measures the size of the array unit.
In the expression array + N (where n =, 2 ,...),
The result of array + N is a pointer. Its type is type * and it points to the class.
Type is type, which points to Unit N of the array. Therefore, sizeof (array + n) is used to measure the pointer.
Type. In the 32-bit program, the result is 4.
Example 11:
Int array [10];
INT (* PTR) [10];
PTR = & array ;:
In the above example, PTR is a pointer and its type is int (*) [10]. The pointer type is
Int [10], we use the first address of the entire array to initialize it. In the statement PTR = & Array
, Array represents the array itself.
The sizeof () function is mentioned in this section, so let me ask, sizeof (pointer name)
Is it the size of the pointer's own type or the size of the type pointed to by the pointer?
The answer is the former. For example:
INT (* PTR) [10];
In a 32-bit program, there are:
Sizeof (INT (*) [10]) = 4
Sizeof (INT [10]) = 40
Sizeof (PTR) = 4
In fact, sizeof (object) measures the size of the object's own type, rather
The type of size.
6. Relationship between pointer and Structure Type
You can declare a pointer to a structure object.
Example 12:
Struct mystruct
{
Int;
Int B;
Int C;
};
Struct mystruct Ss = {20, 30, 40 };
// Declare the structure object SS and initialize the SS members to 20, 30, and 40.
Struct mystruct * PTR = & SS;
// Declares a pointer to the structure object ss. Its type is
// Mystruct *, which points to the type of mystruct.
Int * pstr = (int *) & SS;
// Declares a pointer to the structure object ss. But pstr and
// The type PTR to which it is directed is different.
How can I access the three member variables of SS through the pointer PTR?
Answer:
PTR-> A; // point to the operator, or you can use this operator (* PTR). A. We recommend that you use the former.
PTR-> B;
PTR-> C;
How can I access the three member variables of SS through the pointer pstr?
Answer:
* Pstr; // access a, a member of the SS.
* (Pstr + 1); // access B, a member of SS.
* (Pstr + 2) // access the SS member C.
Although I have adjusted the above Code on my msvc ++ 6.0, you need to know, so that
Pstr is not formal for accessing structure members. To explain why it is not formal, let's
Let's see how to access each unit of the array through a pointer: (replace the struct with an array)
Example 13:
Int array [3] = {35, 56, 37 };
Int * pA = array;
The method to access the three elements of the array through pointer PA is as follows:
* PA; // access to unit 0th
* (PA + 1); // access to unit 1st
* (PA + 2); // access to unit 2nd
In terms of format, it is in the same format as the informal method used to access structure members through pointers.
Sample.
All C/C ++ compilers always store each array unit in the array unit arrangement.
In a continuous storage area, there is no gap between the Unit and the Unit. However
Each Member may require word alignment, double-word alignment, or
For other alignment, you need to add several "fill bytes" between two adjacent members.
As a result, each member may have a gap of several bytes.
Therefore, in example 12, even if * pstr accesses the first
Member variable A cannot guarantee that * (pstr + 1) can access the structure member B. Because the Member
There may be several Padding Bytes between A and B, maybe * (pstr + 1) will access
To fill these bytes. This also proves the flexibility of pointers. If you want
Check whether there are any bytes filled with each structure member. Hey, this is a good method.
However, the correct method for accessing the structure members using pointers is as follows:
Method.
7. Relationship between pointers and functions
You can declare a pointer as a pointer to a function.
Int fun1 (char *, INT );
INT (* pfun1) (char *, INT );
Pfun1 = fun1;
Int A = (* pfun1) ("abcdefg", 7); // call a function through a function pointer.
You can use pointers as function parameters. In a function call statement, you can use a pointer expression
As a real parameter.
Example 14:
Int fun (char *);
INTA;
Char STR [] = "abcdefghijklmn ";
A = fun (STR );
Int fun (char * s)
{
Int num = 0;
For (INT I = 0 ;;)
{
Num + = * s; s ++;
}
Return num;
}
In this example, function fun counts the ASCII value of each character in a string.
And. As mentioned above, the array name is also a pointer. In function call
After being passed as a real parameter to the form parameter S, the STR value is actually passed to S, and s points
The address is the same as the address pointed to by STR, but STR and S respectively occupy their own storage space.
. Adding 1 to S in the function body does not mean that
Add 1 operation.
8. pointer type conversion
When we initialize a pointer or assign a value to a pointer, the left side of the value is a pointer.
A pointer expression on the right of the value pair. In our previous example
In most cases, the pointer type is the same as the pointer expression type.
The type and pointer expression point to the same type.
Example 15:
Float F = 12.3;
Float * fptr = & F;
Int * P;
In the above example, what should we do if we want the pointer P to point to the real number f?
Is the following statement used?
P = & F;
No. Because the pointer P is of the int type *, it points to the int type. Expression
The result of & F is a pointer. the pointer type is float *, and the pointer type is float.
The two are inconsistent. The direct assignment method is not feasible. At least in my msvc ++ 6.0
The value assignment statement of the pointer requires that the types on both sides of the value assignment number be consistent, and the types to be pointed to are also consistent.
I have never tried it on its compiler. You can try it. To achieve our goal, we need
Line "forced type conversion ":
P = (int *) & F;
If there is a pointer P, we need to change its type and the type
Tyep * type, the syntax format is: (type *) P;
In this way, the forced type conversion result is a new pointer, and the type of the new pointer is
Type *. It points to type, and the address it points to is the address pointed to by the original pointer.
All properties of the original pointer P are not modified. (Remember)
If a function uses a pointer as a form parameter
During the combination of parameters, the types must be consistent; otherwise, forced conversion is required.
Example 16:
Void fun (char *);
Int A = 125, B;
Fun (char *) & );
Void fun (char * s)
{
Charc;
C = * (S + 3); * (S + 3) = * (S + 0); * (S + 0) = C;
C = * (S + 2); * (S + 2) = * (S + 1); * (S + 1) = C;
}
Note that this is a 32-bit program, so the int type occupies four bytes, And the char type occupies one
Bytes. Function fun is used to reverse the order of four bytes of an integer. Note:
Are you there? In a function call statement, the result of the real parameter & A is a pointer and its type is
Int *, which points to the int type. The pointer type of the parameter is char *, which points
The type is Char. In this way, we must perform
From int * type to char * type. In combination with this example, we can
Imagine the conversion process of the compiler: the compiler first constructs a temporary pointer char * temp,
Run temp = (char *) & A, and then pass the Temp value to S. So the last
The result is: the type of S is char *, and it points to Char, and the address it points to is
The first address of.
We already know that the pointer value is the address pointed to by the pointer. In a 32-bit program,
The pointer value is actually a 32-bit integer. Can I use an integer as the pointer value?
How about assigning a pointer directly? Like the following statement:
Unsigned int;
Type * PTR; // The type is int, Char, or structure type.
A = 20345686;
PTR = 20345686; // Our goal is to point the pointer PTR to address 20345686
PTR = A; // Our goal is to point the pointer PTR to the address 20345686
Compile it. The result shows that the last two statements are all incorrect. So our purpose cannot be
Reached? No, there are other methods:
Unsigned int;
Type * PTR; // The type is int, Char, or structure type.
A = N // n must represent a valid address;
PTR = (type *) A; // Ha, this is OK.
Strictly speaking, the type * here is different from the type * in the pointer type conversion. Here
The value of the unsigned integer a is treated as an address. Strong above
The value of a must represent a valid address. Otherwise, when you use PTR,
An invalid operation error occurs.
Think about whether or not we can take the address pointed to by the pointer, that is, the value of the pointer, as an integer.
. Yes. The following example shows how to retrieve the value of a pointer as an integer.
And then assign this integer to a pointer as an address:
Example 17:
Int A = 123, B;
Int * PTR = &;
Char * STR;
B = (INT) PTR; // take the pointer PTR value as an integer.
STR = (char *) B; // assign the value of this integer to the pointer STR as an address.
Now we know that we can take the pointer value as an integer, or
To assign an integer as an address to a pointer.
9. pointer security issues
See the following example:
Example 18:
Char S = 'a ';
Int * PTR;
PTR = (int *) & S;
* PTR = 1298;
Pointer PTR is an int * type pointer, which points to the int type. It points
Is the first address of S. In 32-bit programs, s occupies one byte, and INT occupies four
Bytes. The last statement not only changes the byte occupied by S, but also
The three bytes in the high address direction are also changed. What are these three bytes? Only compile the program
The program writer is unlikely to know the program in sequence. Maybe these three bytes are stored in non-
The most important data, maybe the three bytes are exactly a piece of code of the program.
The value of these three bytes is changed! This will cause a collapse error.
Let's take another example:
Example 19:
Char;
Int * PTR = &;
PTR ++;
* PTR = 115;
This example can be fully compiled and executed. But do you see? Clause
After the needle PTR performs the auto-increment 1 operation, the PTR points to the high address direction adjacent to the shaping variable.
. What is in this bucket? We don't know. It may be a non-
Important data may even be a piece of code. The first sentence is written into this storage area.
Enter a data entry! This is a serious error. So when using pointers, the programmer must
I often know where my pointer actually points. When using pointers to access arrays, you must also note that
Do not go beyond the low-end and high-end limits of arrays. Otherwise, similar errors may occur.
In the forced type conversion of pointer: ptr1 = (type *) ptr2, if sizeof (ptr2
Is larger than sizeof (ptr1 type), then ptr2 is accessed using the pointer ptr1.
It is safe to direct to the storage zone. If sizeof (ptr2 type) is smaller
Sizeof (ptr1 type), then use the pointer ptr1 to access the memory pointed to by ptr2
The storage area is insecure. As for why, the readers should think about it in combination with example 18.
White.

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.