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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:56:33+00:00 2026-05-24T13:56:33+00:00

Let’s say you have a string like this: char* a=01234 Letting &a=0000, &(a+1)=0001, &(a+2)=0002,

  • 0

Let’s say you have a string like this:

char* a="01234"

Letting &a=0000, &(a+1)=0001, &(a+2)=0002, and so on, what happens if there is some memory already allocated for another variable at 0007, and you try resizing a to a larger size (a=”0123456789″)? Will a move to a new location that can fit the larger string, or will the data in 0007 be overwritten?

Edit:

I don’t understand what people mean when they say resizing C-style strings is not allowed.

char* a="01234"
cout << &a; //Prints 00FF1360
cout << a;  //Prints 01234
a="0123456789"
cout << &a; //Still prints 00FF1360
cout << a; //Prints "0123456789"

The pointer a didn’t change at all when I reassigned it. It seems like the original string “01234” was just destroyed and “0123456789” replaced it in the same location.

Nevermind, I was printing the location of the pointer rather than the location it was pointing to. As a side question, does anyone know how to print a character pointer’s value without it printing the string instead?

  • 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-24T13:56:34+00:00Added an answer on May 24, 2026 at 1:56 pm

    What you’ve written isn’t C++, and it’s definitely not allowed.

    Correct way:

    const char * a = "01234";  // pointer to array of six const chars.
    char b[] = "01234";        // array of six chars
    

    You can only read the values a[0] to a[5], but never change them. You can change the values b[i] for i in 0 to 5, but be sure not to set b[5] to anything but zero.

    Any access, read or write, to a[i] or b[i] with i greater than five is undefined behaviour and almost definitely suicidal.

    In the case of a, the string literal usually lives in a global, read-only part of memory. On the other hand, b is just an automatic array in the local scope that’s initialized to the given six characters (including terminal zero).

    Conversely, if by some mysterious ways you have already come at the address of some valid area of memory, you could wreak all sorts of havoc:

    char * evil = use_dastardly_exploit();
    memcpy(evil, my_leet_shellcode, 1024);
    

    Indeed C and C++ let you freely roam about your process’s virtual memory space, but you may get shot at any point!

    (For you second question, writing a = "56789"; is fine, but it will set a to point to a different string and not modify the original one (and a should still be of type const char *).)

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say I have table with column 'URL' whrere I store urls like this
Let's say that I have a set of relations that looks like this: relations
Let's say that I have classes like this: public class Parent { public int
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I can call a method like this: core::get() . What is the
Let's say I have this code: <p dataname=description> Hello this is a description. <a
Let's say I have the string: hello world; some random text; foo; How could
Let's suppose I have this piece of code. foreach(string value in myList) { string

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.