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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:07:06+00:00 2026-06-07T06:07:06+00:00

I have seen code that uses arrays of strings in the following way. string

  • 0

I have seen code that uses arrays of strings in the following way.

string *pointer = new string[runtimeAmmount];

I have also seen the individual characters in a string accessed as follows.

string aString = "this";
char bString[] = "that";
bString[3] = aString[3];

The above would result in bString equaling “thas”. This would suggest that a string is actually a pointer to the location of the first character. However a string still has member functions accessed as “string.c_str()” meaning it itself as an object does not follow the rules of a pointer. How does this all work?

Note: My original question was to be different but I figures it out typing it out. If someone could still answer my original question just for verification I would appreciate it. My original question is as follows:
How can an array of strings be new’d if each string can vary in length throughout its lifetime? Wouldn’t the strings run into each other?

The answer I came up with is:
Strings contain pointers to C-style arrays in some way and so the objects take up a set amount of space.

OR

Strings are something of the STL template variety which I have yet to actually take the time to look at.

  • 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-07T06:07:07+00:00Added an answer on June 7, 2026 at 6:07 am

    I will address what is happening in each of the 4 lines of code in your question, but first I should say that your conclusion is not accurate. You are being “fooled” by the operator overloading built into the string class. While it is likely that internally, the string class maintains a C-style character array, this is encapsulated and string is and should be treated as an opaque object, different from a C-style string.

    Now for each of your lines:

    string *pointer = new string[runtimeAmmount];
    

    In this line, pointer is set to point to a newly-allocated array of (empty) string objects. runtimeAmmount is the number of strings in the array, not the number of characters in a C-style string.

    string aString = "this";
    

    This line constructs a new, empty string using the (non-explicit) conversion constructor from the string class: string(const char *). (Note that in a non-construction context, such as aString = "this";, the operator=(const char *) overload of the string class would be used.)

    char bString[] = "that";
    

    This is a typical C-string being treated as an array of characters.

    bString[3] = aString[3];
    

    This uses the overloaded operator[] of the string class to return a character (reference) and then assign it to the 3rd character spot in the C-style character array.

    I hope this helps.

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

Sidebar

Related Questions

I have seen Javascript code that uses parenthesis immediately after a function's closing curly
I have a Nancy JSON REST service that uses the following serialisation code... FormatterExtensions.AsJson(this.Response,
I have seen C# code that uses the @ to tell the compiler the
I have seen sample source code around that uses different ways of releasing/dealloc'ing objects,
I have seen a PHP code that uses shell commands to determinate if this
I typically acquire a character with %c , but I have seen code that
recently I have seen this code arrMove = new List<int[]>(4); m_pppiCaseMoveDiagLine = new int[64][][];
I am new to java, I have seen in the code at many places
I'm trying to test some python code that uses urllib2 and lxml. I've seen
I have seen Ruby code that raises exceptions using a class: raise GoatException, Maximum

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.