+ 2
What is difference btween variable and constant?
6 Réponses
+ 6
Variable mean to vary something or other words u can say that variable is changeable, like: int num = 0; then u can change num's value again like num = 1; now value of num is 1, it can again and again changeable. But constant can not change after it declaration, so constant is unchangeable, mean its not vary.
+ 5
Yeah....and const is read-only variable
int a = 1;//Can write or read
const int a = 1;//Read-only
//Read-only mean you can't change value of variable
whatever
constant is variable too -_-
But this keyword make variable uneditable or read-only
+ 2
Varibles can change whenever you tell it to, but a constant cannot be changed, unless you change the value at declaration.
+ 1
variable can change:
int a = 3;
a = 5;
but constant cant as the following code gives error:
const int a =3;
a =5;//this line throws an exception
+ 1
we able to modify or change value of variable
int a=10;
//first a contains 10
a=20;
but now a contains 20
we not able to change value of constant..
if we try its gives error.
const int a = 10 // a contains 10
a = 20 // its produce error
0
tq guys