Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the GO programming language you can\'t declare a float, it must be a float32

ID: 3763898 • Letter: I

Question

In the GO programming language you can't declare a float, it must be a float32 or float64. Why do you think this is done if the data type is not necessary? Why do you think they used float64 instead of double? Think about the lexical analyzer and how it interprets a symbol. In your own words please explain how the method call f() produces the Fibonacci sequence : package main import "fmt" funcfib() func() int { a, b := 0,1 return func() int { a, b = b, a+b return a } } func main() { f:= fib() // Function calls are evaluated left-to-right. fmt.Println(f(),f(),f(),f(),f() } The output is: 11235

Explanation / Answer

3)

a.

Go is a statically typed language that does not permit operations that mix numeric types. You can't add a float64 to an int, or even an int32 to an int.

b.

Go supports both single (float32) and double (float64) floating point numbers, but float64 is definitely preferred; all math library functions require and return float64.

4)

Functions start with the keyword func, followed by the function's name. The parameters (inputs) of the function are defined like this: name type, name type, etc.

Step 1: In the first call of f(), variable a is assigned to 0 and b is assigned to 1, then a is assigned to b value(i.e, 1) and b is assigned to 1(a+b), return the value of a is 1.

Step 2: Again, in the second call of f(), variable a is assigned to 1 and b is assigned to 2. The value of a is returned to calling function(i.e. 1).

Step 3: In the third call of f(), variable a is assigned to 2 and b is assigned to 3(1+2). The value of a is 2 and is returned to calling function.

Step4: In the fourth call of f(), variable a is assigned to 3 and b is assigned to 5 (2+3). The value of a is 3 and is returned to calling function.

Step5: In the last call of f(), variable a is assigned to 5 and b is assigned to 8(3+5). The value of a is 5 and is returned to the calling function.

So, the result is 1 1 2 3 5