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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:15:27+00:00 2026-05-28T17:15:27+00:00

so I execute this code #include <cstdlib> #include <iostream> int main() { char *test

  • 0

so I execute this code

#include <cstdlib>
#include <iostream>
int main()
{
    char *test = new char[10];
    strcpy(test, "Hello Ther");;
    std::cout << test << std::endl;
    delete[] test;
    std::cout << test << std::endl;
    return 0;
}

and the output is

Hello Ther

Hello Ther

It seems as though the delete[] test statement isn’t doing a thing… No runtime or compile time errors at all

completely stumped me

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

    After you delete[] the array, there is no more array. Any access through that pointer after that has undefined behaviour.

    delete[] is supposed to call the destructors on the array elements and release the storage used by it. Since char has no destructor it simply releases the storage. Releasing the storage only means that it is no longer in use.

    FWIW, there’s one more instance of undefined behaviour in your code. "Hello Ther" has 11 elements: there’s a null ('\0') terminator at the end. strcpying that into a buffer only 10 elements big is undefined behaviour. You need a buffer with space for 11 elements: the 10 characters of “Hello Ther” plus the null terminator.

    This kind of error, a buffer overflow, is a common source of security vulnerabilities. There were famous exploits of this kind of error since at least the 1980s. It would be wise to avoid such unsafe primitives and to prefer safe modern ones (and by “modern” I mean “from the 1990s”), like std::string. Because, you know, this is the 21st century.

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

Sidebar

Related Questions

When i execute this code #include<stdio.h> int main() { int (*x)[5]; printf(\nx = %u\nx+1
my code: #include <iostream> using namespace std; int main() { int n=5; int a[n][n];
I have the following code: #include <stdio.h> main(int argc, char *argv[]) { int n,st;
Let's see the problem by code: code-1 #include <stdio.h> int main(int argc, char *argv[])
I have been trying to execute this program on my MinGW, through Code::Blocks: #include
#include <cstdio> #include <QtCore/QProcess> int main (int argc, char** argv) { // if we
How exactly does fork() work? The following code #include <stdio.h> int main (int argc,
Say you've got the following simple main.cpp file: #include <cstdlib> #include <iostream> #include <fstream>
#include ellison.h int main(int argc, char *argv[]) { if (argc > 1) { int
With doctrine if you execute this code $columns = $accountTable->getColumns(); foreach ($columns as $column)

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.