Q:

Golang Strings | Find Output Programs | Set 1

0

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])
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer Program 1:

Output:

www.includehelp.com
i

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:

105

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:

./prog.go:7:24: invalid argument str[4] (type byte) for len

Explanation:

The above program will generate a syntax error because we cannot use the len() function for the specific character.


 

Answer Program 4:

Output:

19

Explanation:

In the above program, we printed the length of the string "www.includehelp.com" on the console screen.


 

Answer Program 5:

Output:

77

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now