Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ddbf3e4

Browse files
author
Rajeev Kumar Singh
committed
initial commit
0 parents commit ddbf3e4

File tree

14 files changed

+222
-0
lines changed

14 files changed

+222
-0
lines changed

‎.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.iml
2+
.idea

‎Readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Golang Tutorials
2+
3+
1. [Writing your first Go program](https://www.callicoder.com/golang-introduction-hello-world/)
4+
5+
2. [Golang Variables, Zero Values, and Type inference](https://www.callicoder.com/golang-variables-zero-values-type-inference/)
6+
7+
3. [Golang Basic Types, Operators, and Type Conversion](https://www.callicoder.com/golang-basic-types-operators-type-conversion/)
8+
9+
4. [Working with Constants in Golang](https://www.callicoder.com/golang-typed-untyped-constants/)

‎tutorial1- hello-world/hello.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// My first Program
2+
package main
3+
4+
import "fmt"
5+
6+
func main() {
7+
fmt.Println("Hello, World")
8+
}

‎tutorial2-variables/type-inference.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
// Type inference
7+
var name = "Rajeev Singh" // Type declaration is optional here.
8+
fmt.Printf("Variable 'name' is of type %T\n", name)
9+
10+
//================================
11+
12+
// Multiple variable declarations with inferred types
13+
var firstName, lastName, age, salary = "John", "Maxwell", 28, 50000.0
14+
15+
fmt.Printf("firstName: %T, lastName: %T, age: %T, salary: %T\n",
16+
firstName, lastName, age, salary)
17+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
// Declaring Variables
7+
var myStr string = "Hello"
8+
var myInt int = 100
9+
var myFloat float64 = 45.12
10+
fmt.Println(myStr, myInt, myFloat)
11+
12+
13+
//================================
14+
15+
16+
// Multiple Declarations
17+
var (
18+
employeeId int = 5
19+
firstName, lastName string = "Satoshi", "Nakamoto"
20+
)
21+
fmt.Println(employeeId, firstName, lastName)
22+
23+
24+
//================================
25+
26+
27+
// Short variable declaration syntax
28+
name := "Rajeev Singh"
29+
age, salary, isProgrammer := 35, 50000.0, true
30+
31+
fmt.Println(name, age, salary, isProgrammer)
32+
}

‎tutorial2-variables/zero_values.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
var (
7+
firstName, lastName string
8+
age int
9+
salary float64
10+
isConfirmed bool
11+
)
12+
13+
fmt.Printf("firstName: %s, lastName: %s, age: %d, salary: %f, isConfirmed: %t\n",
14+
firstName, lastName, age, salary, isConfirmed)
15+
}

‎tutorial3-basic-types/boolean_types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
import "fmt"
3+
4+
func main() {
5+
var truth = 3 <= 5
6+
var falsehood = 10 != 10
7+
8+
// Short Circuiting
9+
var res1 = 10 > 20 && 5 == 5 // Second operand is not evaluated since first evaluates to false
10+
var res2 = 2*2 == 4 || 10%3 == 0 // Second operand is not evaluated since first evaluates to true
11+
12+
fmt.Println(truth, falsehood, res1, res2)
13+
}

‎tutorial3-basic-types/characters.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
import "fmt"
3+
4+
func main() {
5+
var myByte byte = 'a'
6+
var myRune rune = '♥'
7+
8+
fmt.Printf("%c = %d and %c = %U\n", myByte, myByte, myRune, myRune)
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package main
2+
import "fmt"
3+
4+
func main() {
5+
var a = 3 + 5i
6+
var b = 2 + 4i
7+
8+
var res1 = a + b
9+
var res2 = a - b
10+
var res3 = a * b
11+
var res4 = a / b
12+
13+
fmt.Println(res1, res2, res3, res4)
14+
}

‎tutorial3-basic-types/integers.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
import "fmt"
3+
4+
func main() {
5+
var myInt8 int8 = 97
6+
7+
/*
8+
When you don't declare any type explicitly, the type inferred is `int`
9+
(The default type for integers)
10+
*/
11+
var myInt = 1200
12+
13+
var myUint uint = 500
14+
15+
var myHexNumber = 0xFF // Use prefix '0x' or '0X' for declaring hexadecimal numbers
16+
var myOctalNumber = 034 // Use prefix '0' for declaring octal numbers
17+
18+
fmt.Printf("%d, %d, %d, %#x, %#o\n", myInt8, myInt, myUint, myHexNumber, myOctalNumber)
19+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /