Transfer from: http://blog.dreambrook.com/soloist/archive/2004/12/331.aspxc/c is a very strange thing, what is it delegate? For char Array [N] (N is a constant), there are probably such semantics: <1> char * const (notice is const char *) <2> char [n]
For example, the following (Win2000 Pro platform, compilation under VC.NET 7.1): <1> char * p = array; // array indicates that Char * const, p get the first address of the array
Size_t size = sizeof (char [n]); // size is equal to N
<2> char (* p) [n] = & array; // array Indicates Char [n], // p The first address char (* Q) [N] = array; // Compiling errors
Char (* r) [n] = (char (*) [n]) Array; // r Getting is the first address of the array array
<3> char (& P) [n] = array; // array represents char [n]
<4> Void foo (Char a [n]) {int size = sizeof (a); // size == 4 (32-bit system), // because A actually represents char *};
Foo (array); // Array Represents Char * Const <5> Void Foo (& A) [N]); {INT SIZE = SizeOf (a); // size == n};
Foo (array); // array represents char [n]
<6> void foo (char (* a) [n]); {int size = sizeof (* a); // size == n};
Foo (& array); // array indicates char [n]
<7> char * p; array = p; // Compile error "error C2440, unable to convert from char * to char [n]", // So Array represents char [N]
<8> char = 中;; // Compile error "Error C2106, '=' left operating number must be l value", // So Array represents char [n]
(CHAR (&) [N]) Array = Other; // Perform the 32-bit number of four elements indicated by the ARRAY is the same as the array address of the other representative of Other, // This is explained here in char * const
(CHAR (&) [N]) Array = (CHAR [N]) Other; // Performed the 32-bit number indicated by the first four elements of Array after execution, the same number of headers indicated by Other
(CHAR (&) [N]) Array = (CHAR (&) [N]) Other; // After execution, the array array and the head four elements of the Other array are equal (char (* &) [n]) array = (CHAR (*) [n]) other; // (CHAR (* &) [n]) indicates a reference type, / / This reference is associated with a pointer pointing to the char [n] array, // The 32-bit number indicated by the four elements of Array is the same as the number of headers represented by Other.
(__INT64 &) Array = (__INT64 &) Other; // After execution, the array array is equal to the head 8 elements of the Other array.
<9> long i = 0; (long &) array = i; // actually changed the value of the array itself, // is the first 4 elements (32 bits) in the array representative, // therefore array Representing char [n]
<10> long i = 0; (CHAR (&) [N]) i = array; // assumes that the array number of the first addresses are 0x0012FEAc, // The instruction is executed after I == 0x0012FEAC
<11> long i = 0; (CHAR (&) [N]) i = (CHAR (&) [N]) Array; // Perform the value of the after I is equal to the 32 digits represented by the Array head 4 elements (32 Bit system) <12> (char * &) array = "string"; // executing the 32-bit number of four elements represented after execution The 32-bit number representing the // "String" constant string is the same in memory
<13> (CHAR (&) [N]) Array = (CHAR (&) [N]) "String"; // array array head 4 elements are 's',' t ',' r ',' I '
When we carry out the forced conversion such as Char [N]), the effect is comparable to the "Char * const) array conversion, which is interpreted as a pointer to represent the first address. But both still have a subtle difference: sizeof (char [n]) is equal to N, SIZEOF (CHAR * ConST) equal to 4 (32-bit system), and the conversion such as array (CHAR [M]) is not allowed, where M does not equal n. If we enforce the number of group names with some reference type, the compiler will automatically associate the conversion result (reference type) to the memory area starting from the array of first addresses, regardless of the memory area where the array name itself (does it really exist It is an unknown in memory). When we use this forced converted array name to assign the left operation number of the value, change is the array memory area represented by the array name, and the size of the memory area is changed to the reference type, such as __int64 & So size is 8 bytes, and the rest is pushed. Because (CHAR [N]) is basically equivalent to the (Char * const) effect, the result is interpreted as a pointer, so (char (&) [n]) and (char * const &) are basically quite, the result is explained Associate a reference to the pointer. When using (CHAR (&) [N]) Array, the right operand is actually read from the memory area of the Array pop-up address, and then assigns the left operation . This can be explained why (char (&) [N]) array = (CHAR (&) [N]) Other execution Array's head 4 elements of Other. The following is from: http://blog.9cbs.net/HUSTLI/Archive/2003/07/07/19363.aaspx In memory, the allocation of pointers is only occupied by 4 bytes (do not consider other situations such as 16 bits. After all, the most common is 32-bit, ok, okay, let's talk about this problem), but for arrays, it is different. In addition to assigning its own memory unit, save some information to store it. The number of elements. In theory, the compiler can adopt any technique, but in the actual compiler, two more popular techniques are generally used: associated techniques, cookie strategies. The association method is to allocate a static array. There is a compiler to control, put on a map, the keyword can be used in the number of group name valid intervals, the value can be the number of elements, the time to release the memory space, go search accordingly Map, it seems to be a more secure strategy, but it is more slow. Cookie strategy, also known as the transition allocation technology, when no one-time array spatial assignment, add a sizeof (size_t) byte space in a certain location in the array to store the number of elements of the array. This strategy is undoubted, but it is not safe enough, sometimes we can take the value of cookie and modify it, so that the stack space can be destroyed. However, there is an exception here. When the array is passed as a parameter, the number will be automatically used for ordinary pointers, and the benefits of doing this are also obvious: improve efficiency. You can imagine that if you don't make a pointer to pass, the passage of the element will be a big overhead. There is still a very important issue of the pointer, that is, the problem of alignment of the pointer. When you perform your program on the 80x86 processor, this problem is not fatal, but for the vast majority of the chips, this is fatal. It will also have an impact on your application to a certain other environment.