Working with explicit argument indexes

Report a typo

Even if you don't use an argument index with a formatting verb, Go implicitly assigns indexes to verbs. A confusing aspect of formatting verbs is combining implicit and explicit argument indexing.

For example, the following print statement would not print the "d" letter:

fmt.Printf("%[1]s %s %s %[1]s %s\n", "a", "b", "c", "d") // "a b c a b"

Below there are two different fmt.Printf() statements that use explicit argument indexes. Your task is to write the number and the letter that the statements won't print, each one on a new line:

fmt.Printf("%d %[1]d %d %[1]d %[4]d\n", 1, 2, 3, 4)
fmt.Printf("%s %[3]s %s %[1]s %[4]s\n", "a", "b", "c", "d")
Enter a short text
___

Create a free account to access the full topic