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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:23:15+00:00 2026-06-18T09:23:15+00:00

Using this guide I was told that arrays are passed by reference. This holds

  • 0

Using this guide I was told that arrays are passed by reference. This holds when a struct looks like this:

struct Person{
 char* name;
 int id;
}

But is doesn’t when the struct looks like:

struct Person{
 char name[20];
 int id;
}

When using the seconds struct, The name array is copied by value:

struct Person p1 = {"John", 1234};
struct Person p2 = p1;
p2.name[0] = 'L';

// p1.name[0] is still 'K'

Why is this happening?

  • 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-18T09:23:16+00:00Added an answer on June 18, 2026 at 9:23 am

    I was told that arrays are passed by reference.

    That’s not quite true. Arrays aren’t passed at all, no function can take an array as an argument. When you have a function declared

    void foo(int bar[]);
    

    the type of argument that foo takes is actually int *, and when you call it

    int arr[23];
    /* fill arr with meaningful values */
    foo(arr);
    

    a pointer to the first element of arr is passed by value. All function arguments are passed by value in C, without exception.

    Thus when you pass a struct Person to a function, that is passed by value, hence the members of the struct are copied. If one of the members is an array, that is copied too, since it is a part of the struct.

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

Sidebar

Related Questions

I am using this JQuery Ajax Voting system guide as a rough reference but
I am using this guide: http://www.asp.net/mvc/tutorials/mvc-music-store-part-7 Like instructed, I entered to ASP.NET Web Application
So I'm using this guide but having zero luck on testing to decide whether
I am making a test fullscreen application using this guide . However, I am
Trying to install Scrapy on Mac OSX 10.6 using this guide : When running
I am using lazy_highcharts gem and trying to configure live charts. Following this guide
I'm using this guide: http://www.jeffknupp.com/blog/2012/02/09/starting-a-django-project-the-right-way/ To set up my django project. But I'm stuck
I'm using this guide to call stored procedure in my projet which using EF4
I just managed to install the latest php version using this guide Upgrading the
I am trying to set up some embedded forms using this guide. I have

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.