Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Assignments/01_assignment_day1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"fmt"
)

func main() {
var principal float64
var rate float64
var time float64
fmt.Scan(&principal)
fmt.Scan(&rate)
fmt.Scan(&time)
interest := (principal * time * rate) / 100.0
fmt.Printf("Total interest on amount %f with rate %f for time %f is : %f\n", principal, rate, time, interest)
}
13 changes: 13 additions & 0 deletions Assignments/02_assignment_day1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"fmt"
"math"
)

func main() {
var r float64
fmt.Scan(&r)
area := math.Pi * math.Pow(r, 2)
fmt.Println("Area of circle with radius :", r, " is ", area)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions 08_anonymous_functions.go → Excercise/08_anonymous_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import (
"fmt"
)

func c(a int) int{
return a
}

func b(c func(int) int,val int) int{
return c(val)
}


func main() {
func() { // this function is anonymous function
fmt.Println("Inside anonymous function")
Expand All @@ -19,4 +28,7 @@ func main() {
return a - b
}(5, 2)
fmt.Println("diff between 5,2 is: ", f)

d:= b(c,5)
fmt.Println("calling a function from another function ,i.e. passing function as a parameter to another function ", d)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions Excercise/12_2_defer_keyword.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"fmt"
)

func main() {
a := 23
defer fmt.Println("Value of a:", a) // print 23 as defer is evaluated here itself
a = 33
}
16 changes: 16 additions & 0 deletions Excercise/12_3_defer_keyword.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"fmt"
)

func main() {
fmt.Println("Example of defer function and the output is", foo())
}

func foo() (result string) {
defer func() {
result = "Change World"
}()
return "Hello World"
}
21 changes: 21 additions & 0 deletions Excercise/13_Arrays.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"fmt"
)

func main() {
arr := [3]int32{1, 2, 3}
fmt.Println("array arr: ", arr)
fmt.Printf("type of arr: %T\n", arr) //Type of an array is size and data type
arr1 := arr
fmt.Println("array arr1:", arr1)
fmt.Println("If arr1 equals to arr: ", arr == arr1) //for array to be equal their type and elements should be same
arr[2] = 24
fmt.Println("array arr: ", arr)
fmt.Println("If arr1 equals to arr: ", arr == arr1) //for array to be equal their type and elements should be same

arr2 := [3][4]int{{1, 2, 3, 4}, {3, 2, 1}}
fmt.Println("two D array arr2:", arr2)

}
34 changes: 34 additions & 0 deletions Excercise/14_Slices.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"fmt"
)

func main() {
arr := [10]int32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
s := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} //basic syntax of slice
slice := arr[:] // 0 to len-1
slice1 := arr[0:] // 0 to len-1
slice2 := arr[:6] //0 to high-1
slice3 := arr[3:8] //3 to 8-1
fmt.Printf("slice length :%d, slice capacity :%d\n", len(slice2), cap(slice2))
slice2 = arr[:8] //resizing slice
fmt.Printf("slice length :%d, slice capacity :%d\n", len(slice2), cap(slice2)) //after resizing
fmt.Println(len(arr))
fmt.Println("slice :", slice)
fmt.Println("s :", s)
fmt.Println("slice1 :", slice1)
fmt.Println("slice2 :", slice2)
fmt.Println("slice3 :", slice3)
slice[0] = 9
fmt.Println("slice after reassignment as it is reference type :", slice)

//making a slice using make function

slice4 := make([]int, 5, 10)
fmt.Println("slice4 :", slice4) //default value of slice is 0

//making slice a nil slice
var slice5 []int
fmt.Println("slice5 :", slice5)
}
145 changes: 145 additions & 0 deletions MCQs/MCQs_Day1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
Day: 01
MCQs

Que 1. What will be the output of the following code execution

package main

import "fmt"

var enabled bool = true

func main() {
var enabled = false

if enabled {
fmt.Println("hey there... !")
return
}

fmt.Println("make enabled true... !")
}

A) compile-time error
B) make enabled true... ! (correct - enabled is false in main)
C) hey there... !
D) None of the above


Que 2. What will be the output of the following code execution
package main

import "fmt"

func main() {
var enabled = true
fmt.Println("hey there...!")
}


A) compile-time error (correct - enabled declared but not used)
B) hey there... !
C) runtime error
D) None of the above

Que 3. How many times you can use a package clause for a single source code file?
A) Once (correct – it gives compile time error if we use more than one package clause)
B) Multiple time
C) Twice
D) None of the above


Que 4. Which one is an executable package?
A) package main with func main (correct – as package main tell compiler to make executable of the current program and execution starts from main)
B) package Main with func Main
C) package exec with func exec
D) None of the above


Que 5. What will be the output of the following code execution

package main

import "fmt"

const PI float64

func main() {
PI = 3.14
radius := 15.00
area := radius * radius * PI

fmt.Printf("The area of a circle is %v\n", area)
}


Compile-time error (correct – as global constant is not initialized as well as assigning value to const after declaration)
The area of a circle is 706.5
Run time error
None of the above





Que 6. What is true about go build command

A) compiles the packages named by the import paths, along with their dependencies, but it does not install the results (correct)
B) When compiling packages, the build ignores files that end in '_test.go'.
C) When compiling a single non-main package, the build compiles the packages but discards the resulting object
D) All of the above


Que 7. go install will compile and installs the packages named by the import paths in the directory named by the
A) GOBIN environment variable
B) GOPATH environment variable (correct)
C) GOROOT environment variable
D) None of the above


Que 8. go fmt command is used to take care of most formatting issues
A) TRUE (correct)
B) FALSE



Que 9. What will be the output following code execution
package main

import "fmt"

const PI float64 = 3.14

func main() {
r := 15
area := PI * r * r
fmt.Printf("The area of circle is : \n", area)
}

A) Compile-time error(correct – Mismatched types error)
B) The area of a circle is 706.5()
C) Run time error
D) None of the above



Que 10. What will be the output of the following code execution
package main

import "fmt"

const PI float64 = 3.14

func main() {
PI = 3.141
r := 15.00
area := PI * r * r
fmt.Printf("The area of circle is : \n", area)
}


E) Compile-time error(correct – as it is trying to reassign to a const variable)
F) The area of a circle is 706.5
G) Run time error
H) None of the above

2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Author @avinilcodes
#This repository contains all the assignments and tasks done in GoLang
#This repository contains all the assignments and tasks done in GoLang