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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:03:59+00:00 2026-05-24T17:03:59+00:00

This is a question based on answers from question: const char myVar* vs. const

  • 0

This is a question based on answers from question:

const char myVar* vs. const char myVar[]

const char* x = "Hello World!";
const char  x[] = "Hello World!";

I understand the difference now, but my new questions are:

(1) What happens to the “Hello World” string in the first line if I reassign x? Nothing will be pointing to it by that point – would it be destroyed when the scope ended?

(2) Aside from the const-ness, how are the values in the two examples differently stored in memory by the compiler?

  • 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-24T17:04:00+00:00Added an answer on May 24, 2026 at 5:04 pm

    Placing "Hello World!" in your code causes the compiler to include that string in the compiled executable. When the program is executed that string is created in memory before the call to main and, I believe, even before the assembly call to __start (which is when static initializers begin running). The contents of char * x are not allocated using new or malloc, or in the stack frame of main, and therefore cannot be unallocated.

    However, a char x[20] = "Hello World" declared within a function or method is allocated on the stack, and while in scope, there will actually be two copies of that "Hello World" in memory – one pre-loaded with the executable, one in the stack-allocated buffer.

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

Sidebar

Related Questions

Based on the answers from this question , I have created a grid from
Based on some answers to this question it appears that +alloc does some behind-the-scenes
Edit: Below is my working code based on the feedback/answers I recieved. This question
This is a further question based on this answer: How can I implement a
Based the accepted answer to this question I've setup a NetBeans/tomcat environment. In testing
This question is based on another question of mine (thankfully answered). So if in
This question is based on the thread . I have the shell function function
This question is based on this thread . Is [---] a comment in Git
This question is based on this thread . I am interested in how Git
This question is based on this thread . The code function man() { man

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.