Sunday, 5 May 2024

"Hello, World!" program in Go:



Certainly! Here's the classic "Hello, World!" program in Go:

go
package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

Explanation:

  • package main: This line declares that this Go file is part of the main package, which is necessary for creating executable programs.
  • import "fmt": This line imports the fmt package from the Go standard library. The fmt package provides functions for formatted input and output, including Println.
  • func main() { ... }: This defines the main function, which serves as the entry point for the program.
  • fmt.Println("Hello, World!"): This line calls the Println function from the fmt package to print the string "Hello, World!" to the console.

To run this program:

  1. Save the code in a file named hello.go.
  2. Open a terminal or command prompt.
  3. Navigate to the directory where hello.go is located.
  4. Run the program using the command go run hello.go.
  5. You should see the output Hello, World! printed on the console

No comments:

Post a Comment

Interactive Report: Introduction to the Internet of Things (IoT) ...

Popular Posts