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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:25:23+00:00 2026-06-09T14:25:23+00:00

How do you pass an array to a function where that function can edit

  • 0

How do you pass an array to a function where that function can edit it’s contents?

like when doing

function(int *x)
 {*x = 10;}

main()
  {int x;
   function(&x);}

how could i do the same using a character array?

whenever I do

   function(char *array[], int *num)
   { int x = *num;
     *array[x] = 'A'; }

   main()
   { char this[5] = "00000"; //not a string
     int x = 3;
     function(&this, &x); }

DEV C++ says

[Warning] passing arg 1 of `function' from incompatible pointer type 

obviously I did something wrong, so please tell me how to fix that. 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-06-09T14:25:25+00:00Added an answer on June 9, 2026 at 2:25 pm

    You should write:

    void function(char array[], int *num)
    {
       int x = *num;
       array[x] = 'A';
    }
    
    void main()
    {
       char my_array[5] = "00000";
       int x = 3;
       function(my_array, &x);
    }
    

    Notation char *array[] is an array of pointers that you do not need here.

    When you pass an array somewhere, you should not take its address. Arrays are adjusted to pointers by default.

    EDIT:

    Function prototypes:

    void function(char array[], int *num);
    void function(char *array, int *num);
    

    are absolutely identical. There is no even minor difference between them.

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

Sidebar

Related Questions

Can i pass the entire POST array into a function and handle it within
I want to be able to pass a string (['parent_array']['child_array']) to a function that
How do I pass an array key to a function to pull up the
I want to pass an array of arbitrary struct pointers and a comparison function
I am trying to pass an array (2d) to a function as an parameter.
I gave up on trying to pass a 2d array to a function, where
in C code I'm stuck to pass an array of struct to a function,
I need to write a function that can read a file, and add all
I tried to write generic function that remove the duplicate elements from array. public
I have this simple function which I pass in an array of strings: function

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.