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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:01:22+00:00 2026-06-11T12:01:22+00:00

I wonder why we can pass structure to C function by value, but we

  • 0

I wonder why we can pass structure to C function by value, but we can never do the same with array (which is passed by address).

When I was learning C, they told me that arrays consume much stack, so it’s not preferred to pass them by value.

But it seems that structures are often (if not always) larger than arrays and are more complex data structure, so this explanation makes no sense for me now !

Can anybody help with as much details as possible ?

  • 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-11T12:01:23+00:00Added an answer on June 11, 2026 at 12:01 pm

    In C, an array is always defined as a pointer to the first position of the array, so by definition, when you are passing an array to a function your are passing its memory address, hence its reference.

    When you define a variable of type struct, you’re allocating all the space in memory needed to to contain this struct, and if you make something like:

    struct a, b;
    ...
    a = b;
    

    You are copying all the values from b to a, and in the same way, when you are passing it to a function, you are copying the values of the original struct to the stack. That’s called passing a parameter by value.

    It’s true what you’re stating in your question. A struct may be more complex than an array, but it’s perfectly possible to pass it as value, and it may be inefficient, but the reason that you can’t pass an array by value is because it is defined as a pointer by default.

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

Sidebar

Related Questions

I wonder how can I search for a certain pattern in file, but only
Out of curiosity, I wonder what can people do with parsers, how they are
I just wonder that can we pass any type of class instances to view
I'm using jQuery UI AutoComplete and I'm I wonder how I can pass along
I wonder how I can make a simple function to make the cursor appear
So in PHP we can do $memcache->get(array('a','b','c')); I wonder what is the limit of
I wonder how can I create a shadow similar to the one found in
I wonder how can I export a Visual Studio C++ project to Qt? I
I'd like to start coding for NVIDIA 3D Vision and wonder where can I
wonder whether someone can help me with the following one... I have a struct

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.