C Strings Questions and Answers

Take Exam

C Strings are one of the most essential topics in C programming, frequently appearing in placement papers and technical interviews. This section on C Strings questions with answers helps you master how strings are stored, manipulated, and used in C programs. Whether you’re preparing for TCS, Infosys, Wipro, or Cognizant, understanding string functions like strcpy(), strlen(), strcmp(), and strcat() is crucial. In competitive exams and programming interviews, questions often test your grasp of character arrays, pointers to strings, and memory allocation issues related to them. Practicing C programming MCQs and string manipulation examples enhances your coding accuracy and logic. Use these curated C programming questions and answers to strengthen your understanding and prepare for company-specific tests or online coding assessments effectively.

C Strings

Showing 10 of 26 questions

1. Which of the following function sets first n characters of a string to a given character?

  • strinit()
  • strnset()
  • strset()
  • strcset()
Show Answer Report

2. If the two strings are identical, then strcmp() function returns

  • -1
  • 1
  • 0
  • Yes
Show Answer Report

3. How will you print \n on the screen?

  • printf("\n");
  • echo "\\n";
  • printf('\n');
  • printf("\\n");
Show Answer Report

4. The library function used to find the last occurrence of a character in a string is

  • strnstr()
  • laststr()
  • strrchr()
  • strstr()
Show Answer Report

5. Which of the following function is used to find the first occurrence of a given string in another string?

  • strchr()
  • strrchr()
  • strstr()
  • strnset()
Show Answer Report

6. Which of the following function is more appropriate for reading in a multi-word string?

  • printf();
  • scanf();
  • gets();
  • puts();
Show Answer Report

7. Which of the following function is correct that finds the length of a string?

  • int xstrlen(char *s) { int length=0; while(*s!='\0') { length++; s++; } return (length); }
  • int xstrlen(char s) { int length=0; while(*s!='\0') length++; s++; return (length); }
  • int xstrlen(char *s) { int length=0; while(*s!='\0') length++; return (length); }
  • int xstrlen(char *s) { int length=0; while(*s!='\0') s++; return (length); }
Show Answer Report

8. The number of bits used in extended ASCII is

  • 7
  • 8
  • 16
  • 32
Show Answer Report

9. Given a declaration and initialization statement as shown below, char a [200] = {'0';} What is the output of the following printf statment ?

  • 48 0 0
  • 44 0 0
  • 46 0
  • 49 0 49 0
Show Answer Report

10. 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]);

  • 1 2 3 4 5 6 7
  • 1 2 3 4 5
  • 1 3 2
  • 1 2 3 0 0 0
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test