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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:20:06+00:00 2026-06-09T11:20:06+00:00

If I declare an array in the global scope, it uses up memory to

  • 0

If I declare an array in the global scope, it uses up memory to store it. However, if I declare an array (I am using two types, one is a char array, while the other is an int array) inside a function (such as setup()) will the memory be freed automatically once the array goes out of scope?

I believe this happens for some variables such as int or byte. I just wanted to know if this applies to arrays as well.

Also, since I read that for programs containing lots of strings, it is best to store them in program space, does a call such as

lcd.print("Hello")

still use up the memory for the “Hello” string after the function ends (assuming that the print function does not store it someplace else)?

  • 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-09T11:20:11+00:00Added an answer on June 9, 2026 at 11:20 am

    As to your 1st question:
    Yes. All variables declared inside a function are only valid inside until the function returns and are released automatically then. This has some implications:

    1. You must not use a pointer to a locally declared variable after the variable went out of scope, for instance, after the function returned. (Don’t return a pointer to a local array from your function!) – It is however perfecly legal to pass that pointer to other functions when calling them from within the declaring block/function.

    2. Local variables are stored on the local stack so that there needs to be enough room left for the stack to grow by the corresponding number of bytes when the function is called.

    3. The amount of memory used by those variables is not accounted for in the calculation of “used” RAM at compile time.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is it possible to declare a variable length array with global scope in objective-c?
I need to declare a global two-dimensional array in C. The size of the
I want to declare an array of handel as the following code: using namespace
I want to declare a global array so I can use this in all
Is it posible to declare a global array of a struct, and add elements
I want to know how i can declare and use a global NSMutable array
I am trying right now to declare a large character array. I am using
Is javascript running on single thread? If I declare a global array, and start
I'm having trouble trying to declare a shared memory array within the kernel. Here's
I have this in a kernel module: /*global scope declared*/ static int array[10]={1,2,3,4,5,6,7,8,9,10}; and

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.