This section contains the Golang strings find output programs (set 1) with their output and explanations.
Program 1:
package main
import "fmt"
func main() {
var str string = "www.includehelp.com"
fmt.Printf("%s\n", str)
fmt.Printf("%c\n", str[4])
}
Program 2:
package main
import "fmt"
func main() {
var str string = "www.includehelp.com"
fmt.Printf("%d\n", str[4])
}
Program 3:
package main
import "fmt"
func main() {
var str string = "www.includehelp.com"
fmt.Printf("%d\n", len(str[4]))
}
Program 4:
package main
import "fmt"
func main() {
fmt.Printf("%d\n", len("www.includehelp.com"))
}
Program 5:
package main
import "fmt"
func main() {
fmt.Println("M"[0])
}
Answer Program 1:
Output:
Explanation:
In the above program, we created a string str initialized with "www.includehelp.com". Then we printed string str and character at index 4.
Answer Program 2:
Output:
Explanation:
In the above program, we created a string str initialized with "www.includehelp.com". Then we printed the ASCII value of character 'i', which is stored at index 4 in the string str.
Answer Program 3:
Output:
Explanation:
The above program will generate a syntax error because we cannot use the len() function for the specific character.
Answer Program 4:
Output:
Explanation:
In the above program, we printed the length of the string "www.includehelp.com" on the console screen.
Answer Program 5:
Output:
Explanation:
In the above program, we printed the ASCII value of "M" on the screen.
need an explanation for this answer? contact us directly to get an explanation for this answer