1.

Write a Go code to compare two slices of a byte.

Answer»

We can do this by USING the Compare() method from the bytes package.

package mainimport ( "bytes" "fmt")func main() { sl1 := []byte{'I', 'N', 'T', 'E', 'R' , 'V', 'I', 'E', 'W'} sl2 := []byte{'B', 'I', 'T'} // Use Compare function to compare slices res := bytes.Compare(sl1, sl2) if res == 0 { fmt.Println("Equal Slices") } else { fmt.Println("Unequal Slices") }}

The output of this code is:

Unequal SlicesConclusion

Golang was developed with the promise of code efficiency for faster software development. Companies have recognized the scope and benefits of Golang and have started to adapt to this language. Some of the notable companies that have already shifted to Golang are Google, Apple, Facebook, Docker, BBC etc. Furthermore, Golang has raised the excitement level of developers in the open-source community as it’s been a while since a NEW language for the backend has been created. DUE to these reasons, the scope of Golang is growing rapidly. 

According to the data in Golang Cafe from 2021, the average salary of golang developers in India starts from ₹819,565 to ₹1,617,391 per annum. The prospects and benefits are amazing! 

References

To Learn Golang:



Discussion

No Comment Found