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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:47:52+00:00 2026-05-26T23:47:52+00:00

char *s = hello; The code above allocates 6 bytes in read-only section of

  • 0
char *s = "hello";

The code above allocates 6 bytes in read-only section of a program (I’ve forgot the name of the section) to store the string hello. Then, s is initialized to point to the first character of the string hello. Modifying the string "hello" is undefined behavior. Besides, "hello" itself is constant in nature. The program doesn’t have permission to change read-only section.

I’m using MS VC++ 2010 Express. My question is, why does the compiler allows s, which is a char *, to point to the constant string? Shouldn’t there be a compiler error? Shouldn’t the compiler force us to use const char *s = "hello"; instead of char *s = "hello";?

Thanks.

  • 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-26T23:47:53+00:00Added an answer on May 26, 2026 at 11:47 pm

    In C, “hello” has type char[]. This is not C++. See this question.

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

Sidebar

Related Questions

#include<stdio.h> int main() { char a[5]=hello; puts(a); //prints hello } Why does the code
I have a string as const char *str = Hello, this is an example
Here is what my book says: char *p=Hello; //pointer is variable, string is constant
#include <stdio.h> #include <string.h> int main(void) { char *w; strcpy(w, Hello Word); printf(%s\n, w);
So...I have the following code: int main(void) { const char *s=hello, world; cout<<&s[7]<<endl; return
Can any one explain why the output of this code is only 'hello' and
Here is a C code snippet char *p=Hello World; int a; char b; printf(%d\n,sizeof(p++));
const char *Greet(const char *c) { string name; if(c) name = c; if (name.empty())
I have one requirement in C. char abc[]=hello; char hello[]=world; Using abc whether we
char* p = hello world; programmers usually assigns the address of an variable to

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.