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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:52:38+00:00 2026-06-10T11:52:38+00:00

I have two integer arrays created at runtime (size depends on the program input).

  • 0

I have two integer arrays created at runtime (size depends on the program input). At some point I need to update the contents of an array with the contents of the other doing some calculations.

First I thought about passing those arrays as parameters to a function because I didn’t find a way to return functions in C (don’t think it’s possible). After realizing that was a bad idea since parameters are not really modifiable as they’re copied to the stack I resorted to change to array pointers instead.

While the function is still empty, this is the code I have:

1st take (code compiles, no errors):

// Elements is just to be able to iterate through their contents (same for both):
void do_stuff(int first[], int second[], int elements) {}

// Call to the function:
do_stuff(first, second, elements);

2nd take, attempt to translate to pointers to be able to modify the arrays in place:

void do_stuff(int *first[], int *second[], int elements) {}

// Call to the function:
do_stuff(&first, &second, elements);

This code lead to some rightful compile time errors, because apparently what I thought to be pointer to arrays were arrays of pointers.

3rd take, what I think it’d be the right syntax:

void do_stuff(int (*first)[], int (*second)[], int elements) {}

// Call to the function:
do_stuff(&first, &second, elements);

Still this code produces compile time errors when trying to access the elements of the arrays (e.g. *first[0]):

error: invalid use of array with unspecified bounds

So my question is regarding the possibility of using an array pointer as a parameter of a function, is it possible? If so, how could it be done?

Anyway, if you think of a better way to update the first array after performing calculations involving the contents of the second please comment about it.

  • 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-10T11:52:40+00:00Added an answer on June 10, 2026 at 11:52 am

    An array decays to a pointer to the data allocated for the array. Arrays are not copied to the stack when passing to functions. Thus, you needn’t pass a pointer to the array. So, the below should function fine.

    // Elements is just to be able to iterate through their contents (same for both):
    void do_stuff(int first[], int second[], int elements) {}
    
    // Call to the function:
    do_stuff(first, second, elements);
    

    The cause of your errors on your second attempt are because int *first[] (and the others like it) are actually of the type array of pointer to int.

    The cause of your third errors are because *first[N] is actually *(first[N]), which cannot be done with ease. Array access is really a facade over pointer arithmetic, *(first + sizeof first[0] * N); however, you have an incomplete element type here — you need to specify the size of the array, otherwise sizeof first[0] is unknown.

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

Sidebar

Related Questions

I have two arrays (a and b) with n integer elements in the range
I have a 2D game that uses two integer arrays to track x and
I have two integer values, x and total. I am trying to find the
I have this strange behavior in my JSP page: I have two Integer variables
In a two dimentional integer space, you have two points, A and B. This
I have two columns in a table that are populated with integer values. For
I have two domain classes. class BillingServiceGroup { Integer billingServiceGroupCode String billingServiceGrpDesc String status
I have two entities A and B. public class A{ @Id @GeneratedValue private Integer
I have two maps of type Map<Long, Integer>, one named oldValues representing the old
Let's say I have two simple models project t.string :title vote t.references :project t.integer

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.