Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite of const - in other words, a writeonly qualifier?

Tags:

People also ask

What is const type qualifier?

The const qualifier explicitly declares a data object as something that cannot be changed. Its value is set at initialization. You cannot use const data objects in expressions requiring a modifiable lvalue. For example, a const data object cannot appear on the lefthand side of an assignment statement.

What is the use of having the const qualifier?

We use the const qualifier to declare a variable as constant. That means that we cannot change the value once the variable has been initialized. Using const has a very big benefit. For example, if you have a constant value of the value of PI, you wouldn't like any part of the program to modify that value.

What is a const in C?

The const keyword allows a programmer to tell the compiler that a particular variable should not be modified after the initial assignment in its declaration.

Can const be redefined?

Constants are block-scoped, much like variables declared using the let keyword. The value of a constant can't be changed through reassignment (i.e. by using the assignment operator), and it can't be redeclared (i.e. through a variable declaration).


I was reading Stroustrup's c++ FAQ and I noticed that, at one point, he had a writeonly qualifier in the language. After some discussion, a colleague and I could only come up with one purpose - side effects, specifically in the case of some memory mapped IO. Is there any other legitimate usage for a writeonly qualifier?