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

  • Home
  • SEARCH
  • 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 7646053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:06:27+00:00 2026-05-31T10:06:27+00:00

I need help in understanding when shall I use the following options char *a

  • 0

I need help in understanding when shall I use the following options

char *a = new char();

and

char *a = new char[sizeof(int)+1];

and how the respective memory freeing calls should be made?

  • 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-31T10:06:28+00:00Added an answer on May 31, 2026 at 10:06 am

    The fist one allocates a single char. You delete it with:

    delete a;
    

    The second one allocates an array of chars. The length you have chosen is a little strange. You deallocate it with:

    delete[] a;
    

    Now… I hope you don’t think you can put a stringified number in the second a (something like "123456", because you’ll need many more bytes. Let’s say at least 12 if an int is 32 bits. There is a funny formula to calculate the minimum length necessary. It’s an approximation of the log10 https://stackoverflow.com/a/2338397/613130

    To be clear, on my machine sizeof(int) == 4, but in an int I can put -2147483648 that is 10 digits plus the -, so 11 (plus the zero terminator)

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

Sidebar

Related Questions

I need some help understanding how 32 bit applications use memory on a 64
I need some help in understanding when and why to use Remote Service instead
I am new to c# and need help understanding what going on in the
I need help understanding the following. Say I have a display that is 854x480
I need help understanding how to demonize a process in Go. package main import
Kind of need help understanding what this code actually outputs. Does it out put
I need some help understanding this bit of code pre { white-space: pre; white-space:
I need some help in understanding what is happening here .I am getting a
I have been trying out Cassandra and need some help in understanding a few
I'm a SQL noob, and I need a little bit of help understanding the

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.