Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8636657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:17:04+00:00 2026-06-12T10:17:04+00:00

I would like to know how to prototype a function that returns a array

  • 0

I would like to know how to prototype a function that returns a array which also takes in an array. after prototyping the array how can i implement it

is this correct?

coffee* getData(*coffe);

int main() {
    coffee cf[256];
    coffee FinalCoffee[256];
    FinalCoffee=getData(cf);
}

coffee getData(coffee objcf[]) {
    for(int i=0;i<SIZE;i++) {
        objcf[i].brand="nescafe";
    }
    return coffee;
}

Plsease do advice me on this. i need to be able to get back array so that i can pass the updated array to another function to process it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:17:05+00:00Added an answer on June 12, 2026 at 10:17 am

    Your code doesn’t even have matching declaration and function definition. This doesn’t work.

    But the following does:

    std::vector<coffee> getData(std::vector<coffee> const& objs) {
        std::vector<coffee> result;
        // Do something to fill result
        return result;
    }
    

    But if, as in your example, you want to manipulate the original array, rather than returning a new one, then it makes more sense to not have a return value at all, and to pass the argument as a non-const reference:

    void manipulateData(std::vector<coffee>& objs) {
        for (auto& obj : objs)
            obj.brand = "nescafe";
    }
    

    As a rule of thumb, try to avoid C arrays in favour of C++ standard library containers. This will make your life much, much easier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like an algorithm for a function that takes n integers and returns
I would like to know that how we can check the available memory in
i would like know some reference. I know i can googling it. but prefer
Would like to know how to hide an div after a set of css3
I would like to know what code to use to convert a double[] array
I would like to know, how can we change the SRC url for IFRAME
I would like to know how I could use jQuery inside a native prototype
I like that in javascript, I can create a function, and then add further
I would like to prototype an object but the problem is, I don't know
Would like to know what a programmer should know to become a good at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.