Skip to content

Instantly share code, notes, and snippets.

@rudradesai200
Last active February 6, 2020 21:01
Show Gist options
  • Save rudradesai200/be876faedb547bb2a4a394df06efbf4f to your computer and use it in GitHub Desktop.
Save rudradesai200/be876faedb547bb2a4a394df06efbf4f to your computer and use it in GitHub Desktop.
Code used on my medium article . Check it out here https://medium.com/@rudra.desai200/how-to-use-const-keyword-in-c-b65ee42cf09
class Dummy {
private:
int X = 0;
const int Y = 1;
public:
//declares method const
int getY() const { return Y;}
//declares return type const
const int getX() { return X; }
//declares return type , method and pointer const
const int* const getYptr() const { return &Y; }
};
int main(){
Dummy d;
const int a = d.getX();
const int * const aptr = d.getYptr();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment