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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:47:01+00:00 2026-05-21T07:47:01+00:00

I have an array a whose values I wish to modify through another function.

  • 0

I have an array a whose values I wish to modify through another function. This is the code that I have:

#include "stdlib.h" 
#include "stdio.h"

void myfunc(int* );

int main() {

    int *a, i;

    a = (int*) calloc(10,sizeof(int));
    myfunc(&a);

    for (i=0; i<10; i++) printf("%d\n", a[i]);

    return 0;
}

void myfunc(int* a) {

    int i;

    for (i=0; i<10; i++) *a[i] = i;
}

Obviously something is wrong with my syntax and I Was wondering if someone could lend me a hand 🙂

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-21T07:47:02+00:00Added an answer on May 21, 2026 at 7:47 am

    In the main function, you’ve got a pointer to an integer, a. Then you pass the address of this pointer to myfunc, but myfunc is expecting a pointer to an int, not a pointer to a pointer to an int. You need to change your call to myfunc to this:

    myfunc(a);
    

    But, you’ve also got a problem inside myfunc. You don’t need to dereference a[i] since that indexes into an array a. These are (effectively) the same thing:

    a[i]
    

    and

    *(a+i)
    

    (This isn’t 100%, I think, because in C pointers and arrays are not completely the same thing, so some expert C programmer can correct me)

    You’re probably just get a bit confused by the collection of syntax around pointers and arrays:

    &a
    *a
    a[i]
    *(a+i)
    

    The first one is the address of a, the second dereferences a as a pointer, the third is an index into an array and the fourth is dereferencing a as a pointer with an offset.

    You would only want to do this *(a[i]) if you had an array of pointers, not a pointer to an int.

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

Sidebar

Related Questions

I have an array of RGB values, whose size I can guarantee to match
I have an array of short whose values range between 0 and the maximum
I have a Numpy array and a list of indices whose values I would
I have an array of numbers that potentially have up to 8 decimal places
I have an array of items that are time sensitive. After an amount of
I have an array of hashes, and I want the unique values out of
I have an array of shorts (short[]) that I need to write out to
I have a list of strings whose values come from a fixed set. I
I have two sequential (non-associative) arrays whose values I want to combine into a
I have a function which must return one dimensional associate array, like $user_info[$index]=value where

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.