The variables present in the method known as the Local Variables
they don't have any default value.They must be initialised.
Basic 3 steps for local variable:-
like this
in the above example , multi declaration of the variable give compile time error you cannot declare variable more than once.
in the above example, you can modify the value of variable ..output:-8
in the above example, you cannot do this compile time error x must be initialised before usage.
wrong order first usage then initialisation gives compile time error....
this is all about local variable.....
they don't have any default value.They must be initialised.
Basic 3 steps for local variable:-
- Declaration
- Initialisation
- Usage
like this
output :- 10
output: 5
5in the above example , multi declaration of the variable give compile time error you cannot declare variable more than once.
in the above example, you can modify the value of variable ..output:-8
in the above example, you cannot do this compile time error x must be initialised before usage.
wrong order first usage then initialisation gives compile time error....
this is all about local variable.....
Wat will be the output of last program .
ReplyDeletecompile time error because we use x without declaration..........
DeleteAnd wat wud be the output .,, if a variable has not been assigned any value ..
ReplyDeleteif a variable is declared inside the main then it will give compile time error and if we declare the variable outside the i.e. globally then it will show the default value.....thanx
Deletefeel free to ask.........any other doubts just ask and sorry for the late reply........
ReplyDeleteExcellent move
ReplyDelete