This content originally appeared on DEV Community and was authored by Gaurav Vala
Hey! I am Currently learning Go Lang, and I am taking some basic Notes on my Notion and though I'd also just publish them here. They are not well thought out or well written but it's just me taking notes from time to time for my reference.
I am taking the Udemy Course by Maximilian Schwarzmüller,
Notes
User Input
- Getting values from users through cli is pretty similar to how it is done in C language
- we can use the Scan() method of the fmt package to do that.
fmt.Scan(&investmentAmount)
- here the investmentAmount is already declared and it has a value in it so to override that we are using the “&” symbol, which is a pointer to the actual variable and here will override the value from user input
- If user dont give any value to the variable, it will be initialized with the default value of the type, for float it will be 0.0
Declaring Variables without initial value
- We can declare a variable without initializing any value to that variable, but for that, we will need to explicitly declare the type of the variable, which required as GO Lang is a statically typed language
- This will be declared using the var keyword and then the variable name and then the type of variable
var years float64
var expectedReturn float64
All Methods to declare variables in GO Lang
const inflationRate = 2.5
var investmentAmount float64 = 1000
var years float64
expectedReturn := 5.5
This content originally appeared on DEV Community and was authored by Gaurav Vala
Gaurav Vala | Sciencx (2024-10-06T06:02:21+00:00) Learning GO: 03. Retrieved from https://www.scien.cx/2024/10/06/learning-go-03/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.