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

  • Home
  • SEARCH
  • 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 6185805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:46:44+00:00 2026-05-24T01:46:44+00:00

Note: I am using the g++ compiler (which is I hear is pretty good

  • 0

Note: I am using the g++ compiler (which is I hear is pretty good and supposed to be pretty close to the standard).


So, I think I’ve learned that passing a pointer-to-an-array or passing the actual array as an argument to another function always results in the passing of a pointer-to-that-array.

Similarly, I think I’ve learned that passing a pointer-to-a-function or passing the actual function as an argument to another function always results in the passing of a pointer-to-that-function.

Is it possible to pass a copy of the array (without explicitly making a copy of the array inside the called function)?

Is it possible to pass a copy of the function (without explicitly making a copy of the function inside the called function)? Is that ever useful? What does that even mean?

I understand the difference between passing an array or its copy; what is the difference between passing a function or its copy?

  • 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-05-24T01:46:45+00:00Added an answer on May 24, 2026 at 1:46 am

    C doesn’t make it possible to pass arrays by value or more generally to copy them (unless by hand). C++ inherits that, so no it is not possible. The better approach would be to use std::array (for C++0x; boost::array is identical and available for C++03), which is a copyable type and can be passed by value.

    int i[] = { 1, 2, 3 }; // type is int[3]
    int j[3] = i; // error: can't copy an array
    // C style would be to let j unitialized and to copy the values of
    // i individually:
    // int j[3]; std::copy(i, i + 3, j);
    
    std::array<int, 3> ii = {{ 1, 2, 3 }};
    std::array<int, 3> jj = ii; // Okay
    

    It is not possible in either languages to copy functions and unlike arrays it is not possible to do it ‘by hand’. ‘Copying a function’ is not meaningful in those languages.


    Is it possible to pass a copy of the function (without explicitly
    making a copy of the function inside the called function)? Is that
    ever useful? What does that even mean?

    In what language would ‘copying a function’ be meaningful?

    Lua allows reading the byte-code of a function and it can be reused at a later point (or in another interpreter altogether) to reconstitute a function. I also assume that Lisp, under appropriate circumstances, can do the same with its code-as-data approach. Note that in both those languages it would not be common to do that and it’s not idiomatic to call it ‘copying a function’.

    This sort of thing is less copying in the int i = j; sense that i is a copy, but is usually closer to the concept of marshalling/serialization. That is to say, the transformation of runtime data* into a more persistent form that can be stored and/or transmitted (e.g. across a network).

    *: in those languages (among others) and unlike in C and C++, functions are data.

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

Sidebar

Related Questions

Note: I am using the g++ compiler (which is I hear is pretty good
Note: I am using the g++ compiler (which is I hear is pretty good
Note: I am using the g++ compiler (which is I hear is pretty good
Note: Using MySQL 4.0, which means no subqueries (at present). I have 2 tables:
Note: Using raw Win32 CreateTheard() API No MFC An interface is simply a pointer
I found the following claim in the documentation for Net::OpenSSH : Note that using
( Note : I'm using Scala 2.7.7 here, not 2.8). I'm doing something pretty
I'm using the Borland (AKA Embarcodegearland) C++Builder 2007 compiler which has a minor bug
Note:I don't mean some theoretical question which don't have any implementation just languages that
Following is some obviously-defective code for which I think the compiler should emit a

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.