Golang Operators & Expressions Quiz

Golang
0 Passed
0% acceptance

40 comprehensive questions on Go's operators and expressions, covering arithmetic, comparison, logical, and bitwise operations — with 12 code examples exploring operator precedence, short-circuit evaluation, and practical usage patterns.

40 Questions
~80 minutes
1

Question 1

What are Go's basic arithmetic operators?

A
+, -, *, /, %
B
+, -, *, /, ^
C
&, |, ^, <<, >>
D
==, !=, <, >, <=
2

Question 2

What is the result of 7 % 3 in Go?

A
1
B
2
C
2.333...
D
Compilation error
3

Question 3

What will this arithmetic expression evaluate to?

go
package main

import "fmt"

func main() {
    result := 10 / 3
    fmt.Println(result)
}
A
3
B
3.333...
C
Compilation error
D
10
4

Question 4

What are Go's comparison operators?

A
==, !=, <, <=, >, >=
B
=, <>, <, >
C
&, |, ^, !=
D
+, -, *, /
5

Question 5

What will this comparison return?

go
package main

import "fmt"

func main() {
    x := 5
    y := 5.0
    fmt.Println(x == y)
}
A
Compilation error
B
true
C
false
D
panic
6

Question 6

What are Go's logical operators?

A
&& (and), || (or), ! (not)
B
& (and), | (or), ~ (not)
C
and, or, not
D
+, -, *
7

Question 7

What does short-circuit evaluation mean in Go?

A
In &&, if left operand is false, right isn't evaluated. In ||, if left is true, right isn't evaluated
B
Operations are performed in parallel
C
Expressions are evaluated from right to left
D
All operands are always evaluated
8

Question 8

What will this short-circuit example print?

go
package main

import "fmt"

func test() bool {
    fmt.Println("test called")
    return true
}

func main() {
    result := false && test()
    fmt.Println("result:", result)
}
A
result: false
B
test called\nresult: false
C
Compilation error
D
panic
9

Question 9

What are Go's bitwise operators?

A
& (AND), | (OR), ^ (XOR), &^ (AND NOT), << (left shift), >> (right shift)
B
&&, ||, !, ~
C
+, -, *, /
D
==, !=, <, >
10

Question 10

What is the result of 5 & 3 (bitwise AND)?

A
1
B
8
C
15
D
0
11

Question 11

What does the left shift operator << do?

A
Shifts bits left by specified positions, filling with zeros
B
Shifts bits right by specified positions
C
Rotates bits left
D
Multiplies by 2
12

Question 12

What will this bitwise operation produce?

go
package main

import "fmt"

func main() {
    x := 12  // 1100
    y := 10  // 1010
    result := x ^ y
    fmt.Println(result)
}
A
6
B
22
C
2
D
14
13

Question 13

What is operator precedence in Go expressions?

A
The order in which operators are evaluated when multiple operators appear in an expression
B
Which operators are executed first in time
C
The speed of operator execution
D
Operator associativity rules
14

Question 14

What is the result of 2 + 3 * 4 in Go?

A
14
B
20
C
11
D
24
15

Question 15

What will this precedence example evaluate to?

go
package main

import "fmt"

func main() {
    result := 10 + 5 * 2 - 3
    fmt.Println(result)
}
A
17
B
26
C
9
D
15
16

Question 16

What is the associativity of most Go operators?

A
Left-associative for most operators
B
Right-associative for all operators
C
No associativity rules
D
Depends on operator precedence
17

Question 17

What does the increment operator ++ do in Go?

A
Increases a variable's value by 1, can only be used as a statement
B
Returns the value then increments
C
Increments then returns the new value
D
Can be used in expressions
18

Question 18

What will this increment code do?

go
package main

import "fmt"

func main() {
    x := 5
    y := x++  // This line
    fmt.Println(x, y)
}
A
Compilation error
B
5 5
C
6 5
D
6 6
19

Question 19

What is the result of true && false || true?

A
true
B
false
C
Compilation error
D
Depends on evaluation order
20

Question 20

What will this logical expression evaluate to?

go
package main

import "fmt"

func main() {
    a := true
    b := false
    c := true
    result := a && b || c
    fmt.Println(result)
}
A
true
B
false
C
Compilation error
D
panic
21

Question 21

What does the bitwise AND NOT operator &^ do?

A
Clears bits in the first operand where corresponding bits in second operand are set
B
Sets bits in both operands
C
Flips all bits
D
Performs logical AND
22

Question 22

What is the result of 15 &^ 10?

A
5
B
25
C
10
D
15
23

Question 23

What will this shift operation produce?

go
package main

import "fmt"

func main() {
    x := 8  // 1000
    result := x << 2
    fmt.Println(result)
}
A
32
B
2
C
16
D
4
24

Question 24

What happens with negative numbers in right shift?

A
Arithmetic shift right fills with the sign bit
B
Logical shift right fills with zeros
C
Compilation error
D
Undefined behavior
25

Question 25

What will this overflow example do?

go
package main

import "fmt"

func main() {
    var x uint8 = 255
    x = x + 1
    fmt.Println(x)
}
A
0
B
256
C
Compilation error
D
panic
26

Question 26

What is the result of comparing NaN values?

A
NaN == NaN is always false
B
NaN == NaN is true
C
Compilation error
D
Depends on the values
27

Question 27

What will this floating-point comparison do?

go
package main

import "fmt"

import "math"

func main() {
    x := math.NaN()
    y := math.NaN()
    fmt.Println(x == y)
}
A
false
B
true
C
Compilation error
D
panic
28

Question 28

What is the result of 1 << 63 for int on a 64-bit system?

A
Undefined behavior
B
Largest negative int value
C
0
D
Compilation error
29

Question 29

What will this complex expression evaluate to?

go
package main

import "fmt"

func main() {
    result := 5 > 3 && 10 < 20 || false
    fmt.Println(result)
}
A
true
B
false
C
Compilation error
D
Depends on short-circuit
30

Question 30

What does the unary ^ operator do when used alone?

A
Bitwise NOT (flip all bits)
B
Exponentiation
C
Logical NOT
D
XOR with itself
31

Question 31

What will this bitwise NOT operation produce?

go
package main

import "fmt"

func main() {
    x := 5  // 00000101
    result := ^x
    fmt.Println(result)
}
A
-6
B
250
C
10
D
Compilation error
32

Question 32

What is the difference between / and % for negative numbers?

A
Go truncates toward zero for both, so -7 / 3 = -2, -7 % 3 = -1
B
Go truncates toward negative infinity
C
Undefined behavior
D
Compilation error
33

Question 33

What will this negative modulo example produce?

go
package main

import "fmt"

func main() {
    result := -7 % 3
    fmt.Println(result)
}
A
-1
B
2
C
1
D
0
34

Question 34

What happens when you shift by more than the word size?

A
The result is 0 for left shift, or the original value for right shift
B
Compilation error
C
Panic
D
Undefined behavior
35

Question 35

What will this large shift do?

go
package main

import "fmt"

func main() {
    x := 8
    result := x << 100
    fmt.Println(result)
}
A
0
B
8
C
Compilation error
D
panic
36

Question 36

What is the result of comparing interface{} values?

A
Can compare if underlying types are comparable, panics otherwise
B
Always false
C
Compilation error
D
Always true
37

Question 37

What will this interface comparison do?

go
package main

import "fmt"

func main() {
    var a interface{} = []int{1, 2}
    var b interface{} = []int{1, 2}
    fmt.Println(a == b)
}
A
panic
B
false
C
true
D
Compilation error
38

Question 38

What is the precedence of bitwise vs arithmetic operators?

A
Bitwise AND, OR, XOR have lower precedence than arithmetic operators
B
Bitwise operators have higher precedence
C
Same precedence
D
No defined precedence
39

Question 39

What will this mixed operator expression evaluate to?

go
package main

import "fmt"

func main() {
    result := 1 + 3<<2 - 2&3
    fmt.Println(result)
}
A
11
B
25
C
3
D
17
40

Question 40

Why is understanding operator precedence important in Go?

A
It prevents bugs in complex expressions and ensures code is read correctly by both humans and compilers
B
It makes code run faster
C
It allows writing shorter code
D
Go doesn't have operator precedence

QUIZZES IN Golang