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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:11:36+00:00 2026-06-14T13:11:36+00:00

I know for sure that function(int *a); function(int a[]); in C are the same,

  • 0

I know for sure that

function(int *a); function(int a[]);

in C are the same, function(int a[]) will be translated into function(int *a)

int *a = malloc(20);
int b[] = {1,2,3,4,5};

These two are not the same, the first is a pointer, the second is an array. What happens when I call function(b)?(function(int *a))
I know that b is on the stack, so how is passed to that function?

Secondly, strings:

char *c1 = "string";
char c2 [] = "string";

In this case I don’t know where is c1, and I suppose that c2 is on the stack.
Suppose that function now is: function(char *c), which is the same as function(char c[]), what happens when I call function(c1), and function(c2), the strings will be passed by reference or value?

  • 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-14T13:11:37+00:00Added an answer on June 14, 2026 at 1:11 pm

    There’s a crucial point to make here, everything is really passed by value for example, this will pass a copy of a to foo() (which happens to be a pointer to some memory):

    int *a = malloc(20);
    foo(a);
    

    That’s why if you do something like this in foo() it doesn’t really change the pointer a in main() but changes the local copy:

    foo(int *a)
    {
      a = NULL; /*changes local copy of the pointer*/
    }
    

    In other words, you can use foo()‘s local copy of a to change the memory pointed to by ‘a’ but not to change what a points to in main().

    Now, to pass something “by reference” you pass a copy of a pointer-to-pointer to the function (something like a->b->memory):

    int *a = malloc(20);
    foo(&a);
    

    So when you assign to it in foo() to changes the pointer in main():

    foo(int **a)
    {
      *a = NULL; /*changes the pointer in main */
    }
    

    Now to answer some of your other questions, when you use an array name it is converted to a pointer to the first element of the array:

    int *a = malloc(20);
    int b[] = {1,2,3,4,5};
    foo(a);
    foo(b);
    

    The last two function calls are equivalent in that they both pass a pointer to the first element of some memory, the difference is the memory for a is allocated on the heap, the memory of b however, is allocated on the stack.

    Finally, strings, the following are similar, in that the same principle applies, however the first one is a constant string literal and should be defined as const and you should not attempt to modify it anywhere but you can change the second one:

    const char *c1 = "string";
    char c2 [] = "string";
    

     

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

Sidebar

Related Questions

I'm not sure I know how to ask this. say I have a function
I know that __stdcall functions can't have ellipses, but I want to be sure
Is it safe to left task unreferenced if i know for sure that it
Do you know if it is possible to make sure that a JavaScript script
I'm sure most of you know that a nested loop has O(n^2) complexity if
I know that there are listeners in JavaFX, and i'm sure Java. But I'm
This is something that I'm sure I should know the answer to, but either
I'm sure there's something obvious I'm missing here, but I know that popover controls
the problem starts with a function call to a mono function that is not
I know that the C# Random class does not make true random numbers, but

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.