About Memory:
1. How do I get memory, i.e how are variables declared. Any specific facts and constrains about variables ?
Basic data types are here.Declare the variables which you'll need outside the entry point of main function. Something like :
var (
ToBe bool = false
MaxInt uint64 = 1<<64 - 1
z complex128 = cmplx.Sqrt(-5 + 12i)
)
2. How do we get the entry point for the program execution ? [ Example : main() in the C program ]
func main() --> is the entry point of the program execution.
3. How does dynamic memory handled ? Is it supported in first place ?
Yes dynamic memory is supported.
4. What are the datatypes which are supported and its range?
[Reference] [Go's structs are superior to class based inheritance]
In Go, structs are the way to create user-defined concrete types. The design of the struct type is unique compared to other programming languages.
In simple terms, a struct is a collection of fields or properties. Unlike other object-oriented languages, Go does not provide a “class” keyword. Instead, in Go you’ll find structs — a lightweight version of classes. A struct type is exported into other packages if the name of the struct starts with a capital letter. Unlike other object-oriented languages, you don’t need to provide getters and setters on struct fields, as they can access from the same package and can access from other packages as well, if the name of the fields start with a capital letter.
6. How do you cast from one data type to other data type ?
[Related]
[Reference]
_________________________________________________________________________________
About Program Control :
1. What are the program control options available ? [ like "IF ELSE" , "Switch Case ]
Iterative Statements :
[Reference]
go lang has only one iterative statement i.e "for" loop :
package main
import "fmt"
func main() {
sum := 0
for i := 0; i < 10; i++ {
sum += i
}
fmt.Println(sum)
}
Conditional Evaluation Statement :
a. If statement
[Reference]
package main
import "fmt"
func main() {
if 7%2 == 0 {
fmt.Println("7 is even")
} else {
fmt.Println("7 is odd")
}
if 8%4 == 0 {
fmt.Println("8 is divisible by 4")
}
if num := 9; num < 0 {
fmt.Println(num, "is negative")
} else if num < 10 {
fmt.Println(num, "has 1 digit")
} else {
fmt.Println(num, "has multiple digits")
}
}
Here’s a basic example.
You can have an if statement without an else.
A statement can precede conditionals; any variables declared in this statement are available in all branches.
b. Switch statement
[Reference]
2. How are Boolean operations supported ?
3. What is the operation precedence applied in compile operation ?
[Reference]
_________________________________________________________________________________
Program refactoring :
1. How do you subprogram ?
[Reference]
Can be passed by value and pointers as in the reference link.
3. What are the ways in which multi threading applications are created in the programs ?
Can be done by
[Reference]
4. How are subprograms called , what are the options we have got ?
Normal calls and call by name as in here.
_________________________________________________________________________________
1. How do I get memory, i.e how are variables declared. Any specific facts and constrains about variables ?
Basic data types are here.Declare the variables which you'll need outside the entry point of main function. Something like :
var (
ToBe bool = false
MaxInt uint64 = 1<<64 - 1
z complex128 = cmplx.Sqrt(-5 + 12i)
)
local variables can be declared as shown as example in explanation of FOR loop.
2. How do we get the entry point for the program execution ? [ Example : main() in the C program ]
func main() --> is the entry point of the program execution.
3. How does dynamic memory handled ? Is it supported in first place ?
Yes dynamic memory is supported.
new
allocates zeroed storage for a new item or type whatever and then returns a pointer to it.Go has garbage collection. This means the Go runtime checks in the background if an object or any other variable is not used anymore and if this is the case, frees the memory.4. What are the datatypes which are supported and its range?
bool string int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 uintptr byte // alias for uint8 rune // alias for int32 // represents a Unicode code point float32 float64 complex64 complex128
[Reference] [Go's structs are superior to class based inheritance]
In Go, structs are the way to create user-defined concrete types. The design of the struct type is unique compared to other programming languages.
In simple terms, a struct is a collection of fields or properties. Unlike other object-oriented languages, Go does not provide a “class” keyword. Instead, in Go you’ll find structs — a lightweight version of classes. A struct type is exported into other packages if the name of the struct starts with a capital letter. Unlike other object-oriented languages, you don’t need to provide getters and setters on struct fields, as they can access from the same package and can access from other packages as well, if the name of the fields start with a capital letter.
[Related]
[Reference]
_________________________________________________________________________________
About Program Control :
1. What are the program control options available ? [ like "IF ELSE" , "Switch Case ]
Iterative Statements :
[Reference]
go lang has only one iterative statement i.e "for" loop :
package main
import "fmt"
func main() {
sum := 0
for i := 0; i < 10; i++ {
sum += i
}
fmt.Println(sum)
}
a. If statement
[Reference]
package main
import "fmt"
func main() {
if 7%2 == 0 {
fmt.Println("7 is even")
} else {
fmt.Println("7 is odd")
}
if 8%4 == 0 {
fmt.Println("8 is divisible by 4")
}
if num := 9; num < 0 {
fmt.Println(num, "is negative")
} else if num < 10 {
fmt.Println(num, "has 1 digit")
} else {
fmt.Println(num, "has multiple digits")
}
}
Here’s a basic example.
You can have an if statement without an else.
A statement can precede conditionals; any variables declared in this statement are available in all branches.
b. Switch statement
[Reference]
package main import ( "fmt" "runtime" ) func main() { fmt.Print("Go runs on ") switch os := runtime.GOOS; os { case "darwin": fmt.Println("OS X.") case "linux": fmt.Println("Linux.") default: // freebsd, openbsd, // plan9, windows... fmt.Printf("%s.", os) } }
2. How are Boolean operations supported ?
3. What is the operation precedence applied in compile operation ?
[Reference]
_________________________________________________________________________________
Program refactoring :
1. How do you subprogram ?
package main
import "fmt"
func add(x int, y int) int {
return x + y
}
func main() {
fmt.Println(add(42, 13))
}
2. What are argument passing paradigms supported for subprograms ?import "fmt"
func add(x int, y int) int {
return x + y
}
func main() {
fmt.Println(add(42, 13))
}
[Reference]
Can be passed by value and pointers as in the reference link.
3. What are the ways in which multi threading applications are created in the programs ?
Can be done by
syscall.ForkExec()
from the syscall
package.[Reference]
4. How are subprograms called , what are the options we have got ?
Normal calls and call by name as in here.
_________________________________________________________________________________
Comments
Post a Comment