Intro Flashcards
First statement of any go program
package
e.g. package main
Is package name a String?
No, package name is identifier
Executable vs Library programs in Go
Executable: These are compiled into executable files, which can be executed in future.
Library: These are consumed/called inside the executable program
Different characters included in “White space”
- Tabs
- Spaces
- New Line
How to consume code of other package inside our package?
Using “import” statement. The package name should always be inside the “double quote”.
e.g. import “fmt”
Types of comments in Golang
Single line: //
Multi line : /* */
Function declaration
- Start with keyword “func”
- Followed by function name
- Followed by parenthesis
- Followed by return type, nothing if void
- Followed by body
e.g.
func main() {
}
How to read documentation of library programs?
Using following command:
go doc packageName // with or without double quote
What is the full form of “fmt” package?
Formatted I/O
What are the different boolean values supported by Go?
Only two - “true” and “false” (both small case)
Is GO a statically typed language or Dynamically typed language ? What that means?
Go is a STATICALLY typed language, which simply means, it must know the “types” of all values before running the code.
Which function and package is required to find the type of any value ?
Package: “reflect”
Function: “TypeOf”
How to declare a variable in Go when we don’t know the value?
Use the keyword “var” followed by “name” of the variable followed by it’s “type”
»> var myVar int
How to initialize a variable during declaration and after declaration ?
After declaration:
»> var myVar bool
»> myVar = true
During declaration
»> var myVar bool = true
OR
»> var myVar = true
During declaration we can omit the “TYPE” of the variable, as it will be automatically assigned by the value itself.
What will be the value of the variables, if we don’t initialize it?
It will be the ZERO value of the TYPE. The “Zero” value will be different for different types. Following are the Zero values of different types:
int -> 0
rune -> ‘’
string -> ““
float -> 0
bool -> false