Showing posts with label String Constants/Literals. Show all posts
Showing posts with label String Constants/Literals. Show all posts

Sunday, January 24, 2016

String Constants/Literals

String constants consist of any number of consecutive characters in enclosed quotation marks ("). String constants can have any valid character as part of it, including escape sequences. Example of string literal is given below
"Hello World!"
Some string constants can span multiple lines like the one given below
"First line \nSecond line \nThird line"
// Above statement when printed will look like as given below
First line 
Second line 
Third line
If you want to declare a string constant with quotation marks or backslash as part of the string, then you have to include proper escape character (\) for that. For example if you want a double quote (") as part of your string (like - Press the "Enter" button) you can do it as given below