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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:47:48+00:00 2026-05-23T13:47:48+00:00

I need to edit a variable (array) that is defined outside of the function,

  • 0

I need to edit a variable (array) that is defined outside of the function, so I can use it in another function further in. The easiest way I can think of is to define it as global inside the function, but I have many required files involved as well.

The documentation of global variables says that it can be used “anywhere in the program.” Does that imply throughout all files (is it global in a sense of across all files) or is it just the file it’s in (locally global, if that makes sense).

I did find a question about globals on this site that suggests passing it by reference, but I have this function implemented extensively in other files and requiring them to have an additional variable in their calls would be obnoxious to say the least.

  • 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-23T13:47:49+00:00Added an answer on May 23, 2026 at 1:47 pm

    If a lot of functions grouped in a file require access to some common state, chances are you need to turn them into a class. That’s pretty much the definition of a class.

    Or you could turn the array into a class and have functions call methods on it.

    Perhaps a singleton or a registry (2) could help.

    Note that most OOP implementations pass a reference to the object as a method’s first parameter, hidden (C++, PHP) or not (C, Python).

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

Sidebar

Related Questions

I need to edit XML files on a small Linux box that we have
edit: I need advice on best way to search with regex in vim and
how can I put a INT type variable to a wchar array ? Thanks
Are there performance disadvantages when I use a single-element array over a simple variable?
What I need to happen is have the top5 variable array get used for
I need to edit the web.config file on a live Sharepoint environment, but I'm
I need to edit (using javascript) an SVG document embedded in an html page.
I need to edit format for JFormatedTextField in a Java program. NetBeans are helping
I need to edit or completely replace outline data (bezier curves) of OpenType fonts.
I need to pack all my js, but need to edit it going into

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.