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 9149673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:30:33+00:00 2026-06-17T11:30:33+00:00

I am learning C++ and was reading a book on it where I came

  • 0

I am learning C++ and was reading a book on it where I came across this:

struct Vector{
   int size;
   double* elem;
}

void vector_init(Vector& v, int s){
   v.size = s;
   v.elem = new double[s];
}

So here, would void vector_init(Vector v, int s), without the reference operator, be wrong? Do I have to manually pass by reference using & while passing objects, structs, arrays or anything else as parameters? Also are there any alternate ways to do this? like say void vector_init(Vector *v, int s)?

Any help is appreciated.

  • 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-17T11:30:34+00:00Added an answer on June 17, 2026 at 11:30 am

    would void vector_init(Vector v, int s), without the reference operator, be wrong?

    If you don’t pass v by reference, a copy of v will be made when enters function vector_init and you operate on that copy. After vector_init returns that temporary copy will be destroyed, so vector_init has no effect to your original v. To manipulate on original v, you need to pass v by reference(same to other type).

    Also are there any alternate ways to do this? like say void vector_init(Vector *v, int s)?

    Pass by reference is better choice compare to pass by pointer.

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

Sidebar

Related Questions

I was just reading through Learning Python by Mark Lutz and came across this
I'm reading this book on C# and .NET and I'm learning a bunch of
While reading Learning Perl , I came across a problem about regular expressions. In
I was recently reading a book as prep for an interview and came across
I was reading a learning python book, and this was in one of the
I'm learning the Linux kernel and reading the book The Linux Kernel . Can
I'm learning Java by reading the online Java book, but im finding it hard
I have been reading from the book The C Programming Language learning C, and
I'm reading the Llama ( Learning Perl ) book, and working on the exercises.
I'm learning by reading this tutorial: Link Here's the code: <?php require_once 'Zend/Loader.php'; class

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.