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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:20:46+00:00 2026-05-26T19:20:46+00:00

Here is what my book says: char *p=Hello; //pointer is variable, string is constant

  • 0

Here is what my book says:

char *p="Hello"; //pointer is variable, string is constant
*p='M'; // error
p="bye"; // works

Well, in C my second line does not give me any error, Neither in C++.

I am using Turbo C++ on windows 7. Now is the above thing true if i try in gcc or something else.

Also on the similar lines if the above code is correctly interpreted by the book,

#include<iostream.h>
void display(char*);
void display(const char*);
void main()
{
char* ch1="hello";
const char *ch2="bye";
display(ch1);
display(ch2);
}

void display(char* p)
{
cout << p << endl;
}

void display(const char* p)
{
cout << p << endl;
}

Now is my book considering char* and const char* the same because if it is then the above code shall not work, since arguments will be the same?

(Though i get the output Hello bye on turbo +windows.)

Which one is correct?

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

    The language specification is not a promise that compilers make to you, but a mutual contract that you and compilers both sign onto. (Metaphorically speaking, of course. Obviously it’s not a literally legally binding contract.) If you violate the contract by writing *p='M';, then you’ve triggered “undefined behavior”, and you can’t expect any specific behavior from the compiler: maybe it will be strict about it and give you a compile error, maybe it will just go wonky at run-time . . . you didn’t hold up your end of the bargain, and it’s allowed to do literally whatever it wants now. See also: http://catb.org/jargon/html/N/nasal-demons.html.

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

Sidebar

Related Questions

Well, here we are. Yet another proposed practice that my C++ book has an
I'm downloaded the code from John Papa's book here: http://silverlight-data.com/ and am sucessfully running
Here is a code form a PHP+MySQL book I am reading and I am
Here is a validation script from a book I am learning, Why is escaping
Here's an excerpt from a book I'm reading about application design with MVC: Ideally,
Here is an extract from item 56 of the book C++ Gotchas: It's not
Here's an easy one straight from the text book I can't seem to find.
Here's a sort of odd question. I'm in the process of writing a book
I'm new here to stackoverflow, so bear with me. I have a book that
I'm a little lost (still working with Ron Jeffries's book). Here's a simple class:

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.