In the past, I always thought array was a very simple thing. Recently I read some documents to learn the details that I didn't pay attention to before. Note:
1. array Definition
Int A [Max] = {0}; int main (){{.... /* omitted */int A [Max] = {0}; return 0; return 0 ;}}
The preceding twoProgramAn integer array is defined. Generally, there is no difference. However, when the max value in the experiment is large enough, the max value in the program on the left is greater than the maximum value that can be obtained by Max on the right. This tells us:If you need a large array, we recommend that you define the array outside of the main function, rather than within it. If it is defined within Main, the array will exit unexpectedly if it is slightly larger.
2. assign values between Arrays
We know two arrays of the same type, int A [10], B [10], copy an array to another array, partially or all.
# Include <iostream> # include <string. h> // the header file using namespce STD for the function memcpy; int main () {int A [10], B [10] = {0}; // You can also do this: memset (B, 0, sizeof (B); For (INT I = 0; I ++; I <10) A [I] = I; memcpy (B,, sizeof (INT) * 10); For (INT I = 0; I ++; I <10) cout <B [I] <"; return 0 ;}
You can also copy all of the above copies:
Memcpy (B, A, sizeof (INT) * 5);/* The first five elements, corresponding to the first five B in the same position [0] --- B [4] */memcpy (B + 1, A, sizeof (INT) * 5 ); /* copy the first five elements of A to B [1] --- B [5] */