Character Array MCQ 7 : Null Character , String Length & Backslash Character




Character Array MCQ 7 : Null Character and String Length


What is the Output of the Following Program ?

#include<stdio.h>
#include<string.h>
int main()
{
char str[] = "abctdef\0ghi";
printf("Length : %d",strlen(str));
printf("String : %s",str);
return(0)'
}

Options :

  1. Length : 13
    String : abctdef\0ghi
  2. Length : 8
    String : abc def\0ghi
  3. Length : 8
    String : abc def
  4. Length : 7
    String : abc def

Output:


Switch to String MCQ Home : Click Here


Note:
  • Back Slash Characters Occupies Single Byte i.e Similar With Character.
  • Compiler Ignores any Character Written after ‘\0’
  • While Considering String Length ‘\0’ is Ignored. [i.e “abc\0” has Length = 3 ]
  • These [Backslash Characters] are Considered as Single Character.