Also, array

Source: Internet
Author: User

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] */

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.