C Strings Questions and Answers

Practice Mode
Showing 10 of 26 questions
Q1
Which of the following function sets first n characters of a string to a given character?
  • A strinit()
  • B strnset()
  • C strset()
  • D strcset()
Answer: Option B
Q2
If the two strings are identical, then strcmp() function returns
  • A -1
  • B 1
  • C 0
  • D Yes
Answer: Option C
Q3
How will you print \n on the screen?
  • A printf("\n");
  • B echo "\\n";
  • C printf('\n');
  • D printf("\\n");
Answer: Option D
Q4
The library function used to find the last occurrence of a character in a string is
  • A strnstr()
  • B laststr()
  • C strrchr()
  • D strstr()
Answer: Option C
Q5
Which of the following function is used to find the first occurrence of a given string in another string?
  • A strchr()
  • B strrchr()
  • C strstr()
  • D strnset()
Answer: Option C
Q6
Which of the following function is more appropriate for reading in a multi-word string?
  • A printf();
  • B scanf();
  • C gets();
  • D puts();
Answer: Option C
Q7
Which of the following function is correct that finds the length of a string?
  • A int xstrlen(char *s) { int length=0; while(*s!='\0') { length++; s++; } return (length); }
  • B int xstrlen(char s) { int length=0; while(*s!='\0') length++; s++; return (length); }
  • C int xstrlen(char *s) { int length=0; while(*s!='\0') length++; return (length); }
  • D int xstrlen(char *s) { int length=0; while(*s!='\0') s++; return (length); }
Answer: Option A
Q8
The number of bits used in extended ASCII is
  • A 7
  • B 8
  • C 16
  • D 32
Answer: Option B
Q9
Given a declaration and initialization statement as shown below, char a [200] = {'0';} What is the output of the following printf statment ?
  • A 48 0 0
  • B 44 0 0
  • C 46 0
  • D 49 0 49 0
Answer: Option A
Q10
Given a declaration and initilization as shown below, char a [6] = {'1', '2', '3', }; What is the output of the following printf statement ? printf ("%c %c %c %c %c", a[0], a[3], a[4], a[2], a[4], a[1]);
  • A 1 2 3 4 5 6 7
  • B 1 2 3 4 5
  • C 1 3 2
  • D 1 2 3 0 0 0
Answer: Option C
Questions and Answers for Competitive Exams Various Entrance Test