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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:51:09+00:00 2026-05-23T17:51:09+00:00

Being that my C++ isn’t that great, this may be a really simple/obvious answer,

  • 0

Being that my C++ isn’t that great, this may be a really simple/obvious answer, but it sure has me stumped. Keep in mind its kinda late here and I’m a little tired. I got this code here:

void TestFunc(int *pVar)
{
    cout << endl << *pVar << endl;
    delete pVar;
    pVar = nullptr;
}

int main(int argc, char *argv[])
{
    int *z(new int);

    *z = 5;
    TestFunc(z);
    if (z == nullptr)
        cout << "z Successfully Deleted!" << endl;
    else cout << "z NOT deleted!" << endl;
    return 0;
}

The program compiles just fine with no errors or warning. When I run it, it displays 5, just as I’d expect. However, it says z NOT deleted!. I am curious as to why pVar is not getting set to nullptr even though I explicity set it in my TestFunc() function. Any help would be appreciated. If it matters, this is Visual Studio 2010 and just a regular unmanaged C++ application.

  • 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-23T17:51:09+00:00Added an answer on May 23, 2026 at 5:51 pm

    Because it’s being passed by value (i.e. as a copy).

    If you want the variable itself to be passed (rather than just its value, which is copied), use

    void TestFunc(int *&pVar)
    

    instead.

    Note that delete only cares about the pointee, not the pointer. So “deleting” a copy of a pointer deletes the same thing as the original pointer, because in either case you’re deleting their targets, which are the same.

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

Sidebar

Related Questions

I understand that creating too many threads in an application isn't being what you
I have a question about Excel! I hope that isn't too unconventional for this
I don't know if this is an obvious bug, but while running a Python
I understand that JavaScript isn't really made to open and save files. The best
I have a problem that confuses my users, being that although an item is
I'm writing an application that runs things to a schedule. Idea being that the
I am trying to determine the size of a UITableCellView. The reason being that
I know that being open source does not necessarily makes a program more/less secure
We're being told that fewer HTTP requests per page load is a Good Thing.
I'm trying to group the following string into three groups. 0:0:Awesome:awesome That being "

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.