Printf MCQ 1 : Backslash Characters in C



Printf MCQ 1 : Backslash Characters in C


Predict the Output of the Following Program ?

#include<stdio.h>
void main()
{
printf("\nDiicket");
printf("\bter");
printf("\rCr");
}

Options :

  1. DiicketterCr
  2. Cricketer
  3. CricketCr
  4. Dicketer

[toggle title=”Output”]Cricketer[/toggle]


Switch to Printf MCQ Home :  Click Here


How and Why ?

  1. Properties of Backslash Characters
  2. \n – Newline [ Moves Cursor Position to Next Line ]
  3. \b – Back Space [ Moves Cursor Position to 1 character Back ]
  4. \r – Linefeed [ Moves Cursor Position to First Position in Same Line ]
  5. Diicket is Printed .
  6. \b Causes Cursor Position to Move on Last ‘t’. and then “er” is Printed Final String is “Diicketer”
  7. \r Causes Cursor to Move on First Position in Same Line and then “Cr” is Overwritten on “Di” So Finally Output is “Cricketer”