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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:00:58+00:00 2026-06-14T08:00:58+00:00

I have this code int main() { char A = ‘E’; const char *

  • 0

I have this code

int main()
{
    char A = 'E';

    const char * i;

    i = &A;

    A = 'B';

}

which actually compiles with MSVC, why?
Isn’t a const char * supposed to point to a constant character variable? Why can I change A to ‘B’ in the last line?

Am I missing something?

  • 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-14T08:00:59+00:00Added an answer on June 14, 2026 at 8:00 am

    There is a difference between a constant of type char being pointed to (a.k.a. the pointee) and a constant pointer of type char*. If you want to protect a pointer from (accidental) modification, you can declare it constant:

    char* p = '...';
    char* const cp = 'Hello, World!'; // a constant pointer
    cp[1] = ','; // okay, the pointee is not constant
    cp = p;      // error, the pointer is constant
    

    A variable pointer to a constant can change:

    char *p = '...';
    const char* pc = 'Hello, World!'; // pointer to a constant
    pc[1] = ','; // error, the pointee is constant
    pc = p;      // okay
    

    And finally, you can declare a constant pointer to a constant with

    const char* const cpc = 'Hello, World!';
    cpc[1] = 'a'; // error, pointee cannot change
    cpc = p;      // error, pointer cannot change
    

    This is from §5.4.1 of “The C++ Programming Language”, Stroustrup.

    You can change A to 'B' in the last line, because A is of type char and therefore can be changed. It isn’t declared a const char, which would prevent you from doing so.

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

Sidebar

Related Questions

I have this code which does the trick: #include <stdio.h> int main() { int
i have this piece of code int main() { char a[100]; a[0]='a'; a[1]='b'; fun(a[0]);
I have this code: int main() { char ch[15]; cout<<strlen(ch)<<endl; //7 cout<<sizeof(ch)<<endl; //15 return
I have this code: int main() { char buffer[10]; if( buffer ) { return
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
I have this code: int main(){ char vector[52]; char i; /* initialize the vector
I have this code: int indexOf(const char *array[], char *e) { printf(inside: %d\n,(int)sizeof(array)); /*
I have this code in C++, which returns outputs the following number int main(int
I have this code in C: int main(){ char a[10]; _asm{ mov DWORD PTR[a],eax;}
I have this code: #include <iostream> #include <mp4.h> int main (int argc, char *

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.