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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:59:54+00:00 2026-06-02T13:59:54+00:00

This is a follow on question to an earlier one. I have learned some

  • 0

This is a follow on question to an earlier one.

I have learned some errors of my ways, but have extra questions. My objective is to have a local array in one method changed from another method without the use of any global variables.

void methodOne(){

        int myArray[10] = {0};
        int *pMyArray = myArray;
        
        methodTwo(&*pMyArray);
}

This should be declaring an array of null values and passing a reference to the second array as I was shown how to do so correctly here.

void methodTwo(int *passedPointer){
       
        int *localPointer =  passedPointer;

}

Next I’d like to change the values of myArray from methodTwo. So to change the first [0] element I would say:

*localPointer  = 1;

Is this correct?

Then to change the next element would I increment the pointer using:

localPoint++;
*localPointer = 2;

Would this change the second value in myArray? I’m not sure thats the correct way to do it is it?

TIA

  • 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-02T13:59:57+00:00Added an answer on June 2, 2026 at 1:59 pm

    Yes, this all looks like it should work. Generally when you’re passing an array to a function, you don’t assign to a local variable first though — you just pass the name of the array as the parameter: methoTwo(myArray);. The compiler will automatically convert the name of the array to a pointer to the beginning of the array.

    Also note that you can use array-style notation on the receiving end, something like:

    localpointer[0] = 1;
    localpointer[1] = 2;
    

    …is also reasonable and will accomplish the same as your

    *localpointer = 1;
    ++localpointer;
    *localpointer = 2;
    

    For what it’s worth, another alternative would be:

    *localpointer++ = 1;
    *localpointer = 2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a follow-up to my earlier question I have written a script which
This question follows an earlier one . Here is some code that reproduces the
this is a follow-up question to my question earlier this day . I have
This is a follow up to the question I asked earlier. Basically I have
This is a follow-up question to this question I asked earlier. Btw thanks Neil
This is a follow-up to an earlier question I posted on EF4 entity keys
This is a follow-on question from the one I asked here . Can constraints
this is a follow-up question of mine. Suppose now I have a URL :
This is a follow-up question to this one . Consider this example: #include <iostream>
This is like a follow-up question to this one . Basically what I'm doing

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.