Go Printing to Stdout and Stderr: Difference between revisions
Jump to navigation
Jump to search
Line 25: | Line 25: | ||
fmt.Printf("Hello %s", "Bob") | fmt.Printf("Hello %s", "Bob") | ||
</syntaxhighlight> | </syntaxhighlight> | ||
* <tt>[https://golang.org/pkg/fmt/#Printf fmt.Printf()]</tt> | |||
Prints according to a format specifier. Format specifier documentation https://golang.org/pkg/fmt | |||
===Pointers=== | |||
<pre> | |||
fmt.Printf("%p\n", sPtr) | |||
</pre> | |||
"%p" prepend the "0x" prefix. | |||
Pointers can be also represented using "%X" (base 16, upper case characters). | |||
===Ints=== | |||
<pre> | |||
fmt.Printf("%d\n",i) | |||
</pre> | |||
===Characters=== | |||
<pre> | |||
fmt.Printf("%c\n",i) | |||
</pre> | |||
===Boolean Values=== | |||
<pre> | |||
fmt.Printf("%t\n",b) | |||
</pre> |
Revision as of 00:48, 19 August 2023
Internal
Bootstrapping Functions
Both print()
and println()
are pre-declared functions, ready to use without any import.
print()
println()
func main() {
println("something")
}
fmt.Printf()
import "fmt"
// ...
fmt.Printf("something")
Format Strings
The format strings contain conversation characters (ex. %s
):
fmt.Printf("Hello %s", "Bob")
Prints according to a format specifier. Format specifier documentation https://golang.org/pkg/fmt
Pointers
fmt.Printf("%p\n", sPtr)
"%p" prepend the "0x" prefix.
Pointers can be also represented using "%X" (base 16, upper case characters).
Ints
fmt.Printf("%d\n",i)
Characters
fmt.Printf("%c\n",i)
Boolean Values
fmt.Printf("%t\n",b)