+ 1

Const in c

Why should I define a variable as const if it won't change value? Will it get less memory or what?

18th Jun 2019, 1:12 PM
Lighton
Lighton - avatar
5 Respostas
+ 8
Constant values usually allow for faster access because they can be stored in read-only sections of the memory. And it prevents that your values get changed by accident (or someone with bad intentions)
18th Jun 2019, 1:43 PM
Anna
Anna - avatar
0
When you coded Const int var =10; As that time the value of the variable is will be fixed ,you can not change it
18th Jun 2019, 1:23 PM
Pulkit soni
Pulkit soni - avatar
0
I can make just int var=10 and I won't change it. Why should I define it as const?
18th Jun 2019, 1:27 PM
Lighton
Lighton - avatar
0
We use the const keyword when we don't want to change fix value https://code.sololearn.com/cQRVV7VVYjy2/?ref=app Check my following code
18th Jun 2019, 1:29 PM
Pulkit soni
Pulkit soni - avatar
0
Yes but why should it be defined?
18th Jun 2019, 1:31 PM
Lighton
Lighton - avatar