Vector as function return value

Source: Internet
Author: User

In the actual operation, we often encounter the need to return a sequence of strings or a column of numbers, used to use arrays to save the string or number of this column, now we can use vectors to save the data. However, when the amount of data is very large, the use of vector efficiency is relatively low, and do not return the reference, because you are the vector defined in the function. It is common to use vectors as return values, and we can do that by putting them in function arguments and adding references as containers for saving data. Example:


vector<int> fun1 (int num);

Better ways to handle:

BOOL  FUN1 (int num, vector<int> &vec);

This sets the return value of the function to bool, or saves the data in the VEC, using its reference.

The two methods above can achieve the same effect, but the second method is recommended.

Vector as function return value

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: 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.