What are hard coded values and how do we use it in Dart? I need some examples with code and explanation. Thank you, God bless you new to flutter and dart
CodePudding user response:
A hardcoded value is one that is not variable, meaning that it will always evaluate to the same thing.
Let's say that your app is a calculator, and you want it to perform a sum, if you made the user only input the numbers to be summed like first_number and second_number, but the operator was a constant defined in your code like " ", then you can say that the operation is hardcoded, regardless of language.
If instead you could choose from different types of operators (" ", "-", "*", "/") and then you performed a switch case where you evaluate the operator and perform a different operation on first_number and second_number accordingly, then that's dynamic.
CodePudding user response:
A hard-coded value by definition is a value that does not change based on user input. Variables are values that can change.
Example:
int x = int.parse(stdin.readLineSync()); // get input from user
int y = int.parse(stdin.readLineSync()); // get input from user
// user inputs x=4, y=10
print(x y); // answer is 14 based on user input
print(5 2) // answer is 7 because values never change