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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:23:53+00:00 2026-06-01T06:23:53+00:00

If I declare and object inside a for, and for example assign it’s adress

  • 0

If I declare and object inside a for, and for example assign it’s adress to a pointer, when that for ends, would that pointer be pointing to invalid memory? Like it happens at the end of a method with the objects that you declared in that method

  • 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-01T06:23:54+00:00Added an answer on June 1, 2026 at 6:23 am

    Yes, and not just inside for – inside any block.

    For example:

     void bar()
     {
       foo* p;
       {
         foo f;
         p = &f;
       }
       // p no longer points to a valid object, f has ended its lifetime
    

    Same thing with for except that the object will be created/destroyed each time the loop runs.

    Now, if instead you have:

     void bar()
     {
       foo* p;
       {
         foo* f = new foo;
         p = f;
       }
       // p is still valid here, you need to clean up yourself with delete
    

    And if you do that inside a for, you’ll need to be very careful not to leak all those allocations.

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

Sidebar

Related Questions

How to declare a static dictionary object inside a static class? I tried public
It's known that you should declare events that take as parameters (object sender, EventArgs
Why should I declare local variables as 'static' inside a method? Like: static NSString
Most of the examples of the using statement in C# declare the object inside
Is there anyway to declare an object of a class before the class is
I declared a NSArray object in .h file as @property (nonatomic, assign) NSArray *scnArray;
I see this all the time: object literals declared such that some keys are
I have objects with many variables that I declare and explain in the comments.
If I have a list of elements I would like to sort, Java offers
If I need atomic access to an int field inside an object, is it

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.