+ 1

If I write const int x=5; after many lines I again write const int x =10; What will the final value x at end of execution or it will be an error

19th Aug 2016, 6:31 AM
Akshay Sajeev
Akshay Sajeev - avatar
5 Antworten
+ 4
it will be a syntax error, you cannot declare two variables in a scoop with same name, nor you can assign a "const" with new value
19th Aug 2016, 7:50 AM
Shan Ur Raheem
Shan Ur Raheem - avatar
+ 3
it gives you error because after making variable constant you can't modify it in whole program, while using it as local variable you can modify it externally.
18th Sep 2016, 2:57 AM
ABHISHEK GOEL
ABHISHEK GOEL - avatar
+ 2
yes, that is true. variable with the same name is forbidden, so, it will be Error
2nd Sep 2016, 10:13 PM
Miftah smartsystem
Miftah smartsystem - avatar
+ 1
if you are trying to declare two constants with the same name in one class you will get a compile time error.
22nd Aug 2016, 7:03 PM
Taras
- 2
but you can call another const variable x only if you call it in another method (subroutine)
2nd Nov 2016, 9:34 AM
Haplo d'Biggs