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

  • Home
  • SEARCH
  • 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 8887569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:50:28+00:00 2026-06-14T21:50:28+00:00

Does const char * const getName () const { return name ; } means

  • 0

Does

const char * const getName () const
{ 
   return name ;
}

means that getName() returns a constant pointer to a constant character? Since the function is constant , it would not modify any of its arguments.

  • 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-14T21:50:30+00:00Added an answer on June 14, 2026 at 9:50 pm

    Your example,

    const char * const getName() const { return name; }
    

    most likely returns a constant pointer to a constant nullterminated character string (i.e. to the first character in such a string). Technically it’s just a pointer to a char. But such pointers are treated as pointers to nullterminated strings by e.g. cout.

    Since the method is declared const it cannot directly modify ordinary non-mutable members, but it can modify data pointed to by members that are pointers. This means that technically it can modify things that are regarded as parts of the object that it’s called on, if those things are declared mutable or are pointed to by pointers. However, the common convention for a const method is that even if it does some internal changes such as updating a cache, it will not change the object’s externally visible state, i.e. from an outside view it will not appear to have changed the object.

    For C++,

    • Preferentially use a string class such as std::string, in particular to avoid problems with lifetime management of dynamically allocated memory.

    • Don’t use get prefixes, since in C++ they only add more to read (e.g., would you write getSin(x)*getCos(x)?). More generally, name things such that the calling code reads like English prose! 🙂 You may look at it as designing a little language.

    • As a general rule, don’t add const on the top level of a return value, since that prevents move optimizations.

    Also, conventionally one uses a member naming convention such as name_ (note that the underscore is at the end, not at the front, to avoid conflict with a C naming convention) or myName.

    Thus, ordinary in C++ that function would be coded up as

    string name() const { return name_; }
    

    assuming that string is available unqualified in the non-global namespace where this definition resides (which is my preference).

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

Sidebar

Related Questions

How does one pass a const char *path to fts_open? I would like to
Is the pointer returned by the following function valid? const char * bool2str( bool
bool check(const char* pass); Does const mean that I cannot modify char* inside the
I have a method that requires a const char pointer as input (not null
Why does std::runtime_error::what() return const char* instead of std::string const& ? In many cases
struct hostent *gethostbyname(const char *name) Note that hostent.h_addr_list is a field with variant length.
I have a const char* variable which takes values from a function that I
Here comes a stupid question. libpq 's PQerrorMessage function return a char const* char
Why does: const char example; (uint64*)example have a value of 140734799798420 and *(uint64*)example have
I passed a pointer ptr to a function whose prototype takes it as const

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.