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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:47:18+00:00 2026-06-05T19:47:18+00:00

I am having difficulties to remember whether in c++ a local (non static, and

  • 0

I am having difficulties to remember whether in c++ a local (non static, and inside a block) variable defined in the block is destroyed or not as long as a pointer points to it, even after the execution leaves the block.
So if I created a int inside a block, and have a global pointer, and I leave the block, can my pointer still find that int?

I didn’t finding a clear answer to this online, though it’s probably been answered more than once, sorry about that.

  • 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-05T19:47:19+00:00Added an answer on June 5, 2026 at 7:47 pm

    No, you’re in undefined behavior territory.

    I’m assuming you mean something like:

    int* p = NULL;
    {
       int x = 0;
       p = &x;
    }
    //p is a dangling pointer
    

    If you attempt to dereference p after }, you’ll run into trouble (or, worse, you won’t and it will look like it’s working).

    You can however re-assign the pointer, so something like

    p = new int();
    

    is perfectly OK.

    The following would be legal though (as an alternative to allocating dynamic memory with new or malloc):

    int* p = NULL;
    {
       static int x = 0;
       p = &x;
    }
    *p = 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having difficulties creating a query. I have googled a lot but did not
I am having difficulties getting a span tag to work properly inside a table.
I'm having difficulties to understand what happens when ModelState is not valid (EF4.1, database
I'm having difficulties understanding the way sigaction() works. In <signal.h> , sigaction is defined
I am having difficulties importing a script from a directory that is not stored
I am having difficulties grasping the concept of echoing a variable from a database
I'm having difficulties parsing a string. This is the structure I have: Title:Avatar,Year:2009,Rated:PG-13,Released:18 Dec
I am having difficulties figuring out if APPFabric caching or SQL Server should be
I'm having difficulties returning a typed List. For some reason it is returned as
I'm having difficulties removing the lineStyle lines in JTrees using Netbeans. In a standalone

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.