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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:08:24+00:00 2026-06-02T07:08:24+00:00

I understand when using it as follows: int getX() const {…} means that this

  • 0

I understand when using it as follows:

int getX() const {...} 

means that this function will not modify any of the variables used in its body. But what I didnt undertsnad is using const in 2 places, like the following:

const int* getX () const {...}

what’s the use of putting the const keyword before the int*?

  • 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-02T07:08:25+00:00Added an answer on June 2, 2026 at 7:08 am

    Your first interpretation is wrong.

    int getX() const { ... }
    

    is a member function, and it cannot modify any data members or call any non-const for a given instance of the class that has that function.

    const int* getX() const { ... }
    

    returns a const int*, so it limits what you can assign to using it. It is a non-const pointer to const int, so you cannot modify the int it points to, but you can modify the pointer itself. For example:

    const int* i = someInstange.getX(); // getX() returns const int*
    i = someOtherFunction(); // another function returning const int*. OK to reassign i.
    

    So i itself isn’t const, but what it points to is:

    (*i)++; // ERROR!
    

    if you wanted to return a const pointer to const int you would need something like this:

    const int * const getX() {}
    

    The whole issue is further complicated because you can put the first const in different places without changing the meaning. For more information on that, look at this SO question.

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

Sidebar

Related Questions

I understand that I can change a sql table using the follow sp: EXEC
I understand that using the facebook API I need an api key to connect,
I understand that using postgres on osx is a little difficult because it has
I don't understand how using a 'challenge token' would add any sort of prevention:
Ok, I understand that using strings that have special characters is an encoding issue.
Im using Doctrine and i dont quite understand this code here: $this->hasColumn('id', 'integer', 8,
I was trying to understand the floating point representation in C using this code
Lets say we have this really trivial classes: class A { virtual int Function(int
As I've come to understand using $('.whatever').click() only works for items created initially. Additional
I was just trying to understand delegates using the following code. public class delegatesEx

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.