Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Class 08: Variables and Data Types

Go একটি strongly typed এবং statically typed compiled language, যার ফলে প্রতিটি ভ্যারিয়েবলের টাইপ স্পষ্টভাবে নির্ধারিত এবং গুরুত্বপূর্ণ

🧠 Variable Declare করার নিয়ম

Go তে ভেরিয়েবল declare করার তিনটি পদ্ধতি আছে:

1. Short Variable Declaration (: =)

Short declaration (:=) শুধুমাত্র ফাংশনের ভেতরে ব্যবহার করা যায়:

func main() {
    a := 10
}
  • টাইপ উল্লেখ করতে হয় না, Go নিজে থেকে টাইপ নির্ধারণ করে নেয় (Type Inference)৷

2. Explicit Type Declaration

var x int = 10
  • এখানে x explicitly int টাইপের বলে দেওয়া হয়েছে।

3. Implicit Type Declaration

var a = 10
  • টাইপ উল্লেখ করা হয়নি, তবে a এর টাইপ int হিসাবে নির্ধারিত হবে ১০ দেখে।

📘 Data Types

Go ভাষায় বিভিন্ন ধরনের ডেটা টাইপ আছে, যেগুলো মূলত 3 টি ভাগে ভাগ করা যায়।

১. Numeric Types

Go-তে numeric types মূলত তিনটি ভাগে বিভক্ত থাকে।

Integer Types

TypeSizeDescription
intplatform-dependentসাধারন পূর্ণসংখ্যা
int88-bit-128 to 127
int1616-bit-32,768 to 32,767
int3232-bit-2,147,483,648 to 2,147,483,647
int6464-bitখুব বড় পূর্ণসংখ্যা
uintunsigned intধনাত্মক পূর্ণসংখ্যা
uint80 to 255Unsigned 8-bit integer
uint160 to 65535Unsigned 16-bit integer
uint320 to 4 billion+Unsigned 32-bit
uint64বিশাল ধনাত্মক সংখ্যাUnsigned 64-bit

Floating Point Types

TypeDescription
float3232-bit decimal
float6464-bit decimal (default)

Complex Types

TypeDescription
complex64Real + Imaginary (float32)
complex128Real + Imaginary (float64)

২. String Type

  • Represents text.
var message string = "Hello, Go!"

৩. Boolean Type

  • Holds either true or false.
var isGoFun bool = true

✅ Summary Table

CategoryExample Type
Numericint, float64
Booleanbool
Stringstring

✅ Valid Examples with Different Data Types

a := 10           // int
a := 40.34        // float64
a := "Hello"      // string
a := true         // bool
a = false         // bool (reassigned)

⚠️ Note: একই স্কোপে একই ভেরিয়েবলকে বারবার := দিয়ে declare করা যাবে না।

🔒 Constant Declaration

const p = 100

const দিয়ে declare করা ভেরিয়েবল পরিবর্তন করা যাবে না।

[Author : @shahriar-em0n Date: 2025-06-09 Category: interview-qa/class-wise ]