ADVERTISEMENT
ADVERTISEMENT

Explain what are string literals?

Learn the string literals in Go language, and types of string literals.
Submitted by IncludeHelp, on October 04, 2021

A string literal represents a string constant containing a sequence of characters. There are two types of strings literals,

  • Raw string literals:
    The raw string literals are character sequences enclosed within the backquotes (``).
  • Interpreted string literals:
    The interpreted string literals are character sequences enclosed within the double quotes ("").

Consider the below example – demonstrating the examples of raw and interpreted string literals

// Go program to demonstrate the
// examples Raw and Interpreted
// string literal

package main

import (
	"fmt"
)

func main() {
	// Raw string literal
	x := `Hello\tworld\nHow're you?`

	// Interpreted string literal
	y := "Hello\tworld\nHow're you?"

	fmt.Println("x :", x)
	fmt.Println("y :", y)
}

Output:

x : Hello\tworld\nHow're you?
y : Hello	world
How're you?

In the above program, variable x contains the raw string literal and variable y contains the interpreted raw string.

Golang FAQ »

ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.