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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:26:38+00:00 2026-06-01T02:26:38+00:00

Is that safe to do something like this: char* charArray = new char[10]; strcat(charArray,

  • 0

Is that safe to do something like this:

char* charArray = new char[10];  
strcat(charArray, "qwertyuiop");  
charArray[3] = '\0';  
delete [] charArray;

Will everything be deleted? Or that what is after \0 won’t be? I don’t know if I’m leaving garbage.

EDIT: should be strcpy

  • 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-01T02:26:39+00:00Added an answer on June 1, 2026 at 2:26 am

    If you wanted to write strcpy instead of strcat, then that is safe and correct. But it seems you’ve a misconception about delete [] charArray. It doesn’t delete characters, it deletes the memory pointed to by charArray. The memory even after delete [] charArray might contain those characters, it is not guaranteed though.

    However, if you really wanted to write strcat, and it is not a typo, then your code invokes undefined behavior, because charArray contains garbage to which strcat will attempt to concatenate the second string.

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

Sidebar

Related Questions

Is it safe to use something like this to ensure that a directory isn't
I'm trying to build an object that looks something like this: public class MyObject
There is this DB-connection-like object that my web application will need. It is pretty
I know that new-ing something in one module and delete-ing it in another can
I have a case statement that goes a little something like this: case @type
I was wondering if something like this is safe... // Iterating through a <list>
I think it's safe to say everyone loves doing something like this in Rails:
Is it safe to assume that java.util.concurrent.CompletionService.take().isDone() will always return true? If so, why
I'd like to do something like this in ruby: safe_variable = begin potentially_nil_variable.foo rescue
I have a setup that looks like this. class Checker { // member data

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.