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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:25:15+00:00 2026-06-15T05:25:15+00:00

When passing structures to functions what would the prototype / header look like? What

  • 0

When passing structures to functions what would the prototype / header look like? What would they look like when passing members of structures to functions?

For example…

struct a_struct{
int a;
int b;
};

a_struct point;

void f1(a_struct)
void f2(a_struct)

And lets say that I want to pass the whole structure to f1, but just a member to f2. Would I use the data type a_struct as parameter for both? Or would f2 have a different data type because I am only passing the member which is an int. Would this vary for an array of structures? The program I have been tasked to write is supposed to use arrays of structures. I figured that this wouldn’t make much of a difference except that it will be passed by reference automatically.

  • 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-15T05:25:16+00:00Added an answer on June 15, 2026 at 5:25 am

    When passing objects around (not just scalar values), you have to be concerned about memory ownership and copying, etc. This means that you have multiple options for how you declare the interface for your function. For example, you can pass by reference or pass by value.

    A possible declaration for you might be:

    void f1(a_struct& my_struct);
    

    This would pass a reference to the a_struct object and prevent any copying of the object. However, your example structure just contains scalar values, so the possibility of copying the object isn’t cause for too much worry. As a result, this would suffice:

    void f1(a_struct my_struct);
    

    As far as passing a member of the struct into a function, the function would need to be declared to take the type of the member. For example, to pass the a member of the a_struct into a function, you would do:

    void f1(int val);
    

    Finally, arrays do complicate things as they would come in as a pointer to the function. For example, to pass an array of a_struct objects, you would make this declaration:

    void f1(a_struct* my_struct);
    

    However, you could then simply reference the parameter normally. For example:

    my_structs[1];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Passing User defined argument to RPM is possible while installing?. for example: ~>rpm -i
I'm having trouble passing a structure array as a parameter of a function struct
Because I would like to make some tests with the libpcap and a small
So like most new .NET developers you start of passing DataSets everywhere and although
I have a large C structure (about 40 members, int and char[]) which I
Right now, I have many python files. Each has many functions. I'm passing hash
Something that really would like to know but never found out are shortcuts in
I would like to pass the right-hand side of a formula to an R
I would like to add the real time dynamic to my map, by means
i have data structure i am passing this from server to client using data

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.