KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am having trouble finding an intuitive pattern for the way const is used in declarations in the C and C++ languages. Here are some examples: const int a; //Const integer int const a; //Const integer const int * a; //Pointer to constant integer int * const a; //Const pointer to an integer int const * a const; //Const pointer to a const integer In lines 1 and 2, it seems const can come before or after int , which is what it modifies. So how, in line 4, does the compiler decide that const is modifying * (pointer) rather than int ? What is the rule that the compiler follows for deciding which thing the const applies to? Does it follow the same rule for * ?
Tags (comma-separated)
Save Edits
Cancel