📝 Program: main.go

package main

import "fmt"

// 📘 Main function is the entry point of the program.
func main() {
    // 🎯 Declaring an integer variable 'x' and assigning it a value of 5
    var x int = 5

    // 💡 Printing the value of x
    fmt.Println("📌 The value of variable x is:", x)
}

📖 Explanation

Line Code Description
1 package main Declares that this file belongs to the main package (entry point).
3 import "fmt" Imports the fmt package for formatted I/O.
6 func main() { Declares the main function, which Go looks for to run the program.
8 var x int = 5 Declares x as an int and initializes it with the value 5.
11 fmt.Println(...) Prints the value of x to the console.

🚀 How to Run This Program

💻 Prerequisites

🛠️ Steps to Execute

  1. Create a file named main.go:
    touch main.go
    
  2. Paste the code above into main.go.
  3. Open terminal and navigate to the folder where main.go is saved.
  4. Run the program:
    go run main.go
    
  5. ✅ You’ll see the output:
    📌 The value of variable x is: 5
    

🎨 Output (Styled)

🌈 Golang Variable Declaration Demo 🌈
-------------------------------------
📌 The value of variable x is: 5

🧠 Key Takeaways

  • var x int = 5 shows explicit declaration with type and initialization.
  • You could also write it as x := 5 (type inferred) — but here we showcase the explicit var syntax.

Would you like a similar program with user input or a web interface as well?

By Aditya Bhuyan

I work as a cloud specialist. In addition to being an architect and SRE specialist, I work as a cloud engineer and developer. I have assisted my clients in converting their antiquated programmes into contemporary microservices that operate on various cloud computing platforms such as AWS, GCP, Azure, or VMware Tanzu, as well as orchestration systems such as Docker Swarm or Kubernetes. For over twenty years, I have been employed in the IT sector as a Java developer, J2EE architect, scrum master, and instructor. I write about Cloud Native and Cloud often. Bangalore, India is where my family and I call home. I maintain my physical and mental fitness by doing a lot of yoga and meditation.

Leave a Reply

Your email address will not be published. Required fields are marked *

error

Enjoy this blog? Please spread the word :)