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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:38:23+00:00 2026-06-14T11:38:23+00:00

String construct got space for the data by doing new char[strlen(cp)+1]; Since there are

  • 0

String construct got space for the data by doing

new char[strlen(cp)+1];

Since there are only strlen(cp)characters in the string, what is the extra byte for?

  • 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-14T11:38:24+00:00Added an answer on June 14, 2026 at 11:38 am

    For the special '\0' char which indicates end of string.

    (Remember, C-style strings are null-terminated arrays).

    Additional helpful notes:

    • strlen does not count the '\0' (That’s why you need this extra byte).
    • strcpy does copy the '\0'.
    • char str[7] = "String"; – Adds '\0' by itself.
    • char str[] = {'S','t','r','i','n','g'} – Does not add '\0'.
    • char str[7] = {'S','t','r','i','n','g'} – Will add '\0'.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

String class has a constructor: new String(byte[] bytes, Charset charset) and a method: byte[]
I want to construct a string with an array of objects for (int n=0;
I need to construct a long string with javascript. Thats how i tried to
I need to construct the URL of a page in a String, to send
Does anyone know how to construct a format string in .NET so that the
I would like to construct regex (in JavaScript) that would return: for string test
I have a big HTML-string containing multiple child-nodes. Is it possible to construct a
#include stdafx.h int _tmain(int argc, _TCHAR* argv[]) { string s = Haven't got an
My application receive strings from outside and construct an XML document string fromOutside =
I am working in a project that reads files and processes data. There I

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.