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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:19:53+00:00 2026-05-27T16:19:53+00:00

I am getting confused as to whether it is valid (in C) to pass

  • 0

I am getting confused as to whether it is valid (in C) to pass a pointer to an array that has been initiated as follows (e.g. at compile time on the stack):

int a[] = {1, 2, 3};

my_func(&a);


void my_func(int **a)
{
   int *tmp = *a; /* this statement fixes the problem */
   printf("%d %d %d", (*a)[0], (*a)[1], (*a)[2]); /*doesn't work */ 
   printf("%d %d %d", tmp[0], tmp[1], tmp[2]); /*does work */ 
}

when I step through this with gdb I can’t ‘see’ any of the values (*a)[0], etc. from ‘inside’ my_func. e.g.

(gdb) p (*a)[0]
Cannot access memory at address 0x0

I’m thinking that possibly I have a fundamental misunderstanding with regard to what you can and can’t do with arrays that are on the stack rather than the heap?

I hope thats not the case as it is very convenient for my unit tests to declare arrays on the stack as in the example, but I need to test functions that are expecting pointers to pointers to int.

Note I do get a compiler warning as follows:

 test_utility.c:499:5: warning: passing argument 1 of ‘int_array_unique’ from incompatible pointer type [enabled by default]
 ../src/glamdring2.h:152:5: note: expected ‘int **’ but argument is of type ‘int (*)[12]’

but I thought it would be ok to mix int *a[] with **a? Perhaps not? Are they not equivalent?

  • 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-27T16:19:53+00:00Added an answer on May 27, 2026 at 4:19 pm

    a[] is an array, not a pointer (“not an lvalue”); in your function call

    func( &a);
    

    &a decays to a pointer to int; &a is not a pointer to pointer to int. Why? there is no pointer to point to.

    The function prototype

    void func( int **p);
    

    expects a pointer to pointer to int, that does not fit the function being called with a pointer to int as an argument, like you did.

    UPDATE: I don’t know what the OP’s intentions were, so this is just a guess…

    void my_func(int *a);
    
    int a[] = {1, 2, 3};
    
    my_func(a); /* note: this is equivalent to my_func( &a ); */
    
    
    void my_func(int *a)
    {
       printf("%d %d %d\n", a[0], a[1], a[2] ); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting confused with size_t in C. I know that it is returned
I am getting confused with memory allocation basics between Stack vs Heap . As
I am often getting confused with the image sizes and button sizes that I
I'm getting confused with the include/exclude jargon, and my actual SVN client doesn't seem
I'm getting confused by bank switching in PIC assembler... This works for putting a
I'm getting confused re the range of options for development & deploying some simple
I am getting confused between TCP being Connection oriented and UDP being connectionless so
I'm getting confused in the doco how I should be setting up Ninject. I'm
I'm getting confused by pointers in objective-c. Basically I have a bunch of static
A common issue I have is getting confused what $(this) is referring to. I

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.