March 29, 2024

Telugu Tech Tuts

TimeComputers.in

C language learning in telugu Escape sequences Part 4

c language learning in telugu

In C language there are some characters that are not treated as the same. These character combinations that give different results such as a new line, a tab space, or a backspace, are known as escape sequences.

Syntax of Escape Sequences:
Escape sequences in C language start with a backslash () and followed by a character. e.g, to get a new line, ‘n’ is used for this purpose.

Escape Sequences
Result
a Bell (Alert)
n

New line
t Tab Space
f Formfeed
b Backspace
r Carriage Return
Backslash
’ Single Quotation Mark
” Double Quotation Mark
Note: As you see, backslash is used for escape sequences, that’s why it is not treated as backslash by complier, so in order to print a backslash, double backslashes are used i.e (). first is to start escape sequence and second is to print backslash.
Example:
view source
print?

/* A program to print out all the special C escape sequences  */
/* Michael Ashley / UNSW / 03-Mar-2003                        */

#include <stdio.h>  // for printf definition

int main (void) {
    printf ("audible alert (bell) BEL  a   %dn" , 'a');
    printf ("backspace            BS   b   %dn" , 'b');
    printf ("horizontal tab       HT   t   %dn" , 't');
    printf ("newline              LF   n  %dn"  , 'n');
    printf ("vertical tab         VT   v  %dn"  , 'v');
    printf ("formfeed             FF   f  %dn"  , 'f');
    printf ("carriage return      CR   r  %dn"  , 'r');
    printf ("double quote         "    "  %dn", '"');
    printf ("single quote         '    '  %dn", ''');
    printf ("question mark        ?    ?  %dn"  , '?');
    printf ("backslash                  %dn", '');
    return 0;
}

And here is the output it produces, when compiled with gcc on a GNU/Linux computer:

audible alert (bell) BEL  a   7
backspace            BS   b   8
horizontal tab       HT   t   9
newline              LF   n  10
vertical tab         VT   v  11
formfeed             FF   f  12
carriage return      CR   r  13
double quote         "    "  34
single quote         '    '  39
question mark        ?    ?  63
backslash                  92