adsense


Friday, 20 November 2015

C++ LANGUAGE CHARACTER LITERALS PAGE 28

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



C++ LANGUAGE CHARACTER LITERALS







Character Literals 


Character literals are enclosed in single quotes. If the literal 
begins with L (uppercase only), it is a wide character literal 
(e.g., L'x') and should be stored in wchar_t type of variable. 
Otherwise, it is a narrow character literal (e.g., 'x') and can 
be stored in a simple variable of char type. 
A character literal can be a plain character (e.g., 'x'), an 
escape sequence (e.g., '\t'), or a universal character (e.g., '\u02C0'). 
There are certain characters in C++ when they are preceded by 
a backslash they will have special meaning and they are used to 
represent like newline (\n) or tab (\t). Here, you have a list of 
some of such escape sequence codes: 



Escape sequence    Meaning 


\\                  \ character 


\'                  ' character  

\"                  " character 

\?                 ? character 

\a                 Alert or bell 

\b                 Backspace 

\f                 Form feed
 
\n                 Newline 

\r                 Carriage return 

\t                 Horizontal tab 

\v                 Vertical tab 

\ooo                 Octal number of one to three digits 

\xhh . . .        Hexadecimal number of one or more digits 

Following is the example to show a few escape sequence characters: 


#include <iostream>
 
using namespace std; 
 
int main() 
{ 
   cout << "Hello\tWorld\n\n"; 
   return 0; 
} 
 
When the above code is compiled and executed, 
it produces the following result: 

Hello   World 





No comments: