"Z Code Writer" is an Online Blog for Programmer & Beginner. Here, You will Find tech, Build your Programming Skills and other Programming Language Like C, C++, HTML, Java Script Java Code, Web Designing and University Of Sialkot (USKT) CGPA / GPA Calculator etc.

Friday, 19 July 2019

Escape Sequence

Escape Sequence

      The special characters that can be used in format-string in printf() function to control the displaying behavior of the "printf()" function, are called escape sequences. An escape sequence prefixed with the backslash (\) and a code character is used to control the displaying behavior. The backslash (\) is called an escape character. The escape sequence looks like two characters.
      The escape sequences are special non-printing characters. It means that escape sequences are not printed with string.
The escape sequence can be inserted in any position of the format string such as:


  • at the beginning of the string.
  • at the middle of the string.
  • at the end of the string etc.

      For example, the escape sequence '\n' is used to insert a new line. The cursor move from current position on the output device to the beginning of the next line. If escape sequence '\n' is inserted at the beginning of the string then the string will be displayed after printing a blank line e.g.
                printf ( "\nWelcome" ) ;
      The commonly used escape sequences are as follows:


Escape Sequence
Explanation
\n
'n' stands for new line. It is used to insert a new line and cursor moves to the beginning of next line.
\t
't' stands for tab. It moves the cursor one horizontal tab from current tab stop to the next tab stop. For example,
         printf ( "P \ tA \ rK" ) ;
The output of the statement will be as under;
         P      A       K
\a
'a' stands for alarm. It causes a beep sound in the computer.
\b
'b' stands for backspace. It moves the cursor one space back. For example,
         printf ( "Welcome \ b" ) ;
After executing the above statement, the string "Welcome" will be printed and the cursor will move one space back. It means that it will be under the character 'e' of the word "Welcome". In the above statement if '\b' is omitted, then the cursor will be at the end of string. If another output statement is used after the above statement, then the printing will be starting from character 'e' and 'e' will be deleted.
\r
'r' stands for return. It moves the cursor to the beginning of the current line.
\f
'f' stands for feed. It causes the output to feed one paper on the printer attached to the computer.
\\
It is used to display a backslash character in the output. For example,
         printf ( "\ \ PAK \ \" ) ;
The output will be as under:
           \PAK\
If a single backslash character is used, then it is not printed as part of string.
\’
It is used to display a single quotation mark in the output. For example,
         printf ( " \ 'Welcome \ ' " ) ;
The output will be as under:
           'Welcome'
/”
It is used to display a double quotation mark in the output. For example,
         printf ( " \ "Welcome \ " " ) ;
The output will be as under:
           "Welcome"


No comments:

Post a Comment

Thanks For Visiting Here...!! I will Reply you as soon as possible.