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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:09:43+00:00 2026-06-14T08:09:43+00:00

I am aware that in C you can pass (or return) a structure by

  • 0

I am aware that in C you can pass (or return) a structure by value but you cannot pass an array by value. What happens when the structure contains an array? Will the array (that is within the structure) be copied as the structure is passed (or returned) by value? I have run a sample at ideone.com and it works, but I would like to know where in the standard this is covered (and yes, I have looked).

http://open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf

typedef struct
{
    float aValue;
    int anArray[5];
} myStruct;

myStruct addValueToArray(myStruct in)
{
    myStruct out = in;

    int i;
    for (i = 0; i < 5; i++)
    {
        out.anArray[i] = in.anArray[i] + in.aValue;
    }

    return out;
}
  • 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-14T08:09:44+00:00Added an answer on June 14, 2026 at 8:09 am

    Yes, it will be copied. The entire structure is a value, so it can be passed to a function, returned, and (many seem to forget this but you use it, good!) assigned.

    Note that any padding that might be present need not be copied, which makes it possible for = to be faster than a manual call to memcpy() could be, since it can never do that.

    Quite hard to find a single place in the PDF that supports this, but I’m not very experienced in looking. Basically, struct instances are “values” in C’s sense, so most of the talk just automatically covers structs.

    Like:

    (6.2.5, part 1)
    The meaning of a value stored in an object or returned by a function is determined by the
    type of the expression used to access it.

    (6.2.5, part 20)
    A structure type describes a sequentially allocated nonempty set of member objects
    (and, in certain circumstances, an incomplete array), each of which has an optionally
    specified name and possibly distinct type.

    (6.8.6.4, part 3)
    If a return statement with an expression is executed, the value of the expression is
    returned to the caller as the value of the function call expression.

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

Sidebar

Related Questions

I aware that this will be a less programming question, but still... How can
I am aware that I can set null like string val = null; But
I'm aware that I can check an ActiveRecord through the rails console but it
I am aware that you can probably build a lower version of .NET, but
I am aware that you can generate create scripts to generate database objects, but
I am aware that I can access all external links on a page using
I'm aware that you can do this: public ActionResult DoSomething([Bind(Exclude = CreationDate)] Item item)
I'm aware that I can <exec executable=cp failonerror=true> , however, I'd really rather have
I am aware that you can 'remotely' script android using port forwarding, using the
Now I am aware that I probably need to use a ListBox and can

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.