Lessons
Go Introduction
Go Get Started
Go Syntax
Go Comments
Go Variables
- Declare Variables
- Go में Variables का परिचय
- Go में Multiple Variable Declaration
- Variable Naming Rules (नामकरण के नियम)
Go Constants
Go Output
Go Data Types
- Basic Data Types
- Go Boolean Data Type (बूलियन डेटा प्रकार)
- Go Integer Data Types
- Go Float Data Types
- Go String Data Type
Go Arrays
Go Slices
Go Operators
- Go Operators
- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- Logical Operators
- Bitwise Operators
Go Conditions
Go Switch
Go Loops
Go Functions
Go Struct
Go Maps
Project Structure
Arithmetic Operators
Go Arithmetic Operators
Arithmetic operators का उपयोग सामान्य गणितीय operations के लिए किया जाता है।
| Operator | Name | Description | Example |
|---|---|---|---|
| + | Addition | दो values को जोड़ता है | x + y |
| - | Subtraction | एक value को दूसरे से घटाता है | x - y |
| * | Multiplication | दो values को गुणा करता है | x * y |
| / | Division | एक value को दूसरे से भाग करता है | x / y |
| % | Modulus | भागफल का शेष लौटाता है | x % y |
| ++ | Increment | Variable की value 1 से बढ़ाता है | x++ |
| -- | Decrement | Variable की value 1 से घटाता है | x-- |
Code Examples
Addition (+)
package main
import "fmt"
func main() {
x := 10
y := 5
sum := x + y
fmt.Println(sum)
}
15
Subtraction (-)
package main
import "fmt"
func main() {
x := 10
y := 5
diff := x - y
fmt.Println(diff)
}
5
Multiplication (*)
package main
import "fmt"
func main() {
x := 10
y := 5
prod := x * y
fmt.Println(prod)
}
50
Division (/)
package main
import "fmt"
func main() {
x := 10
y := 5
div := x / y
fmt.Println(div)
}
2
Modulus (%)
package main
import "fmt"
func main() {
x := 10
y := 3
mod := x % y
fmt.Println(mod)
}
1
Increment (++) और Decrement (--)
package main
import "fmt"
func main() {
x := 5
x++
fmt.Println(x) // 6
x--
fmt.Println(x) // 5
}
6 5
1. Division में यदि दोनों operand integer हों, तो परिणाम भी integer होगा।
2. ++ और -- केवल standalone statement में use किए जा सकते हैं। जैसे sum := x++ गलत है।
3. Modulus (%) operator केवल integer values के लिए valid है।