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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:22:37+00:00 2026-05-16T22:22:37+00:00

I am a bit confused about the behaviour of a C program from another

  • 0

I am a bit confused about the behaviour of a C program from another programmer I am working now with. What I can not understand is the following:

1) a variable is defined this way

typedef float (array3d_i)[3];
array3d_i d_i[NMAX];

2) once some values are assgined to all the d_i’s, a function is called which is like this:

void calc(elem3d_i d_element);

which is called from main using:

calc(d_i[i]);

in a loop.

When the d_i’s are initialized in main, each element gets an address in memory, I guess in the stack or somewhere else. When we call the function “calc”, I would expect that inside the function, a copy of the variable is created, in anoother address. But I debugged the program, and I can see that inside the function “calc”, the variable “d_elemt” gets the same address than d_i in main.

Is it normal or not?

I am even more confused because later there is call to another function, very similar situation except that now the variables are float type and also an array of them is initialized, and inside the function, the variables are given a different address than the one in main.

How can this be? Why the difference? Is the code or the debugger doing something weird?

Thanks

  • 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-16T22:22:37+00:00Added an answer on May 16, 2026 at 10:22 pm

    Arrays are passed by reference in C, while simple values will be passed by value. Or, rather, arrays are also passed by value, but the “value” of an array in this context is a reference to its first element. This is the “decay” Charles refers to in his comment.

    By “reference”, I mean pointer of course since C doesn’t have references like C++ does.

    C does not have a higher-level array concept, which is also why you can’t compute the length of the array in the called function.

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

Sidebar

Related Questions

I'm a little bit confused about simple program which I wrote, can You please
I'm a bit confused about how many controllers I need, and when I can
I'm a bit confused about inheritance under sqlalchemy, to the point where I'm not
I am a bit confused about how I can exchange information between controllers in
I'm a bit confused about the following. Given this class: public class SomeClassToBeCasted {
Evening, I'm a bit confused about why some of my jquery isn't working. Here's
I am a bit confused about the license. Can anyone tell me if I
I'm a bit confused about the difference between when I just declare a variable
I'm a bit confused about the size of my App! The folder and all
I am a bit confused about the 'rules' of when a TextView element displays

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.