Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Wednesday, August 31, 2011

C-39 : Example of Escape Sequence (\n)

\n is the example of  Escape Sequence.
It's used to print the newline character.
Note that ,\n doesn't appear in the output.
Place \n wherever you want to insert a new line in the output.

See the examples below :
(Eg:-1) :

#include<stdio.h>
#include<conio.h>
void main()
{
            clrscr();
            printf("This\nString\nwill\nbe\nprinted\nin\n8\nlines.\n");
            getch();
}

Output:
This
String
will
be
printed
in
8
lines
===========================================================================
(Eg :-2) :
#include<stdio.h>
#include<conio.h>
main()
            {
            clrscr();
            printf("This is the First Line of Output.");
            printf("But is this the Second\nline of Output?");
            getch();
            }

Output:
This is the First Line of Output. But is this the Second
line of Output?


===========================================================================
(Eg :-3) : 




#include<stdio.h>
#include<conio.h>
main()
            {
            clrscr();
            printf("In how many lines will the output\nof this program be printed?");
            getch();
            }



Output:
In how many lines will the output
of this program be printed?
===========================================================================
(Eg:-4) :


What will be the output of the program ?

#include<stdio.h>
#include<conio.h>
main()
      {
      clrscr();
      printf("\"\\n\", the teacher said,\"is used to  ");
      printf("insert a new line in a C string.\"");
      printf("\n\" I C,I C\",said the blind student.\n");
      getch();
      return 0;
      }

Output:


" \n", the teacher said, "is used to  insert a new line in a C string".
"I C,I C", said the blind student.

(An important point to remember :  ""(Double Quote) character is not an Escape Sequence ).
.


=========================================================================
Back to Home   &  C

No comments: