7.2.4 array parameters

Source: Internet
Author: User

1. the compiler does not check the length of the real parameter Array

2. Pass the array through reference

Void printvalues (INT (& ARR) [10]) {/**... **/}

The compiler checks the size of real parameters.

3. Main: process command line options

Code:
  1. # Include <iostream>
  2. Using NamespaceSTD;
  3. IntMain (IntArgc,Char** Argv)
  4. {
  5. If(Argc! = 3)
  6. {
  7. Cout <"Please input 3 ARGs! ";
  8. }Else{
  9. Cout <"Sum :"<Atof (argv [1]) + atof (argv [2]);
  10. }
  11. }

======================================== 4.20 update ================== ========================

The second parameter defines a C-style string array.

The first parameter defines the number of strings in the array.

======================================== 4.24 update ================== ========================

Array as reference parameter

 

A parameter is used to replace the array name (& ref) in the array definition. The array size must be specified. For example:
int fun (INT (& ARR) [10]);
Note: (& ref) there must be no less parentheses on both sides. Otherwise, Int & arr [10] indicates an array with 10 referenced elements (note: the element type cannot be defined as a referenced array in C ++ ).

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.