0
Const
const int a; What's it? I have questions like this, but I don't study it yet.
9 Answers
+ 1
Const stands for constant. An example would be the irrational number Pi. Itās always the same and is never subject to change.
Defining variables as const acts in the same fashion. A variable marked as const cant have itās value changed after its been defined. There are ways to break the const rule in C++, but that is outside the scope of this conversation.
Hope that helps.
+ 1
This means that variable of type int named a cannot change.
+ 1
Const is used because after you add const int or something the value of that int cannot be changed in redeclaration
Ex:
Const int pie = 3.14;
0
Int a be can't double a?
0
It can be any type but it can't be changed later
0
It means,
const int a =10;
a=a+4;
cout << a;
Output: 10?
0
It rises error becuse you try to change it.
0
int is the type (Pro tip: it's a good idea to be explicit about long or short)
const marks it as a constant (i.e. immutable). Basically, it will give you an error if you try to change it somewhere.
It's useful for constants you use throughout your code, for instance
const maxSize = 100;
in a program where you don't allow arrays (or other data structures such as lists) of size > 100