3
2-bit Server
Int * P = NULL;
What is the value of sizeof (p?4
What about sizeof (* P?4
Here we need to understand the first address of the array and the first address of the array element.
& A, & A [0], A. Although these two addresses are the same, their meanings are indeed different. We can see the difference between & A + 1 and & A [0] + 1. The former indicates: & A [0] + sizeof (INT) * 100, that is, pointing to the first address of the next array with 100 int elements. We can make an experiment to verify it:
Int B [100], a [100];
Printf ("% x, % x/N", (& A + 1), B );
The address should be the same. Note that the variables declared in vc6 are at the high address of the memory, and the declared variables are at the low address. Therefore, the address of a is low, while that of B is high.
The address of a is the same as the address of & A [0]. That is to say, a represents the address of the first element of the array, & A indicates the first address of the array, although their values are the same. Be sure to identify the differences !!
Then it is easier to understand the following example.
Int A [100];
What is the value of sizeof (?400
What about sizeof (A [100? // Pay special attention to this example.4
What about sizeof (&?400
What about sizeof (& A [0?4
Int B [100];
Void fun (int B [1, 100])
{
Sizeof (B); // What is the value of sizeof (B?4
Sizeof (B [100]);4
Sizeof (& B );4
Sizeof (& B [0]);4
}
Int AA [5] = {1, 2, 3, 4, 5 };
Int * ptr1 = (int *) (& AA + 1 );
Int * ptr2 = (int *) (INT) AA + 1 );
Printf ("% x, % x, % x/N", AA + 1, (INT) AA + 1, & AA + 1 );
Printf ("% x, % d/N", ptr1 [-1], * ptr2 );
Note that AA + 1, & AA + 1, (INT) AA + 1 indicate the addresses from AA [0], plus 4 bytes respectively, + Length of the entire array, + 1 byte.
It can be understood as follows:Because AA points to the address of the first element of the array, that is, the AA type is int, so AA + 1 is equivalent to AA + sizeof (INT) * 1, & aa points to the first address of the array, so its type is int [5], so & AA + 1 is equivalent to AA + sizeof (INT [5]) * 1, (INT) AA + 1 is to convert the address of the first element of AA to int type and then to + 1. If the address of the first element of AA is 0x100000, then (INT) AA + 1 is equal to 0x1000000 + 1 = 0x1000001, so you can understand more!
Let's take a look at what the second line of print statements print?
========================================================== ====================
Check the functions of the big end and small end:
1 is a small end, and 0 is a large end.
Int checksystem ()
{
Union check
{
Int I;
Char ch;
} C;
C. I = 1;
Return (C. CH = 1 );
}
Or
Int xx = 1;
If (* (char *) & xx = 1)
Printf ("Little-Endian/N ");
Else
Printf ("big-Endian/N ");
========================================================== ====================
Flexible array (c99 ):
Typedef struct st_type
{
Int I;
Int A [0];
} Type_a;
Or
Typedef struct st_type
{
Int I;
Int A [];
} Type_a;
Type_a * P = (type_a *) malloc (sizeof (type_a) + 100 * sizeof (INT ));
Note sizeof (type_a );
========================================================== ======================
Const modifier:
Ignore the type name first (the type name is ignored during compiler parsing). We can see which const is close. "Near water Building
The first month of the station ", who is near to whom.
Const int * P; // const modifier * p, p is the pointer, * P is the object pointed to by the pointer, immutable
Int const * P; // const modifier * P. P indicates the pointer, and * P indicates the object to which the Pointer Points, which is immutable.
Int * const P; // const modifies p, p is immutable, and P points to the object variable
Const int * const P; // The first const modifier * P, the last const modifier P, the pointer P and P point to the object
Immutable
========================================================== ========================
Unsigned integer variable
1), int I =-20;
Unsigned J = 10;
J + = I;
Printf ("% u/N", J); // 4294967286
What is the value? Why?
2) What is the problem with the following code? (Infinite loop)
Unsigned I;
For (I = 9; I> = 0; I --)
{
Printf ("% u/N", I); // Infinite Loop
}