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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:26:25+00:00 2026-06-19T01:26:25+00:00

How to free memory with something like this (Visual Studio 2008 – Win32/console): I

  • 0

How to free memory with something like this (Visual Studio 2008 – Win32/console):

I can include only: iostream

#include <iostream>

void data_t(char *test[])
{
    test[0] = new char[];
    test[1] = new char[];
    test[0] = "Test1";
    test[1] = "Test2";
}

int main()
{
    char *test[2];
    data_t(test);
    cout<<test[0]<<"\n";
    cout<<test[1]<<"\n";
    delete[] test[0];//Debug assertion failed! - The program '[7884] Zadanie_4_sortowanie.exe: Native' has exited with code 3 (0x3).
    delete[] test[1];
}

What i do wrong?

  • 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-19T01:26:27+00:00Added an answer on June 19, 2026 at 1:26 am

    Since “Test1” and “Test2” are used by your program at runtime (they are printed by cout), the compiler has to save them somewhere. It does this by putting them both into your executable.

    Since they are both in your executable already, there is no reason to allocate any new memory.
    So you can remove the first two lines in data_t.

    If you do this you will get a compiler error, though this error should have already been there, which will complain that you are trying to assign a string literal (“Test1”, “Test2”) to a non const array.

    The problem here is that strings saved by the compiler into the executable are NOT to be modified. You are only printing them, but data_t doesn’t know that. To fix the problem you should use const char * instead of char *

    If you intend to modify these strings, you’ll need to allocate new memory and copy the strings into it.

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

Sidebar

Related Questions

I have an app ,that log print something like this: GC_CONCURRENT freed 433k,7% free
How to free the memory used by the person_map_t multi_indexed_persons_map? I cant find something
Can some suggest a good a free memory profiling tool which will show memory
Is there something like memory friendly scripting in JavaScript? Certain principles I should be
Supposing I have a 2 dimensional array which was created with something like this,
I have a list in C that is something like this: typedef struct _node
I have something like this in my code typedef struct ts_fem_mesh { double **vertices;
I have an application which works something like this in pseudocode: DisplayPrettyUI() DoABunchOfReportingWorkThatAllocatesHundredsOfMB() GC.Collect()
I'm trying to free memory that's reallocated but I get an error... float *
i'm trying to get the actual free memory. It seems to be the easiest

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.