Last active
February 6, 2020 21:01
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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