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

21. What will be the output ? char st [ ] = "India"; char *p; strcpy (p, st); printf("%s and %s are same", st, p);

  • India and India are same
  • India and <some Garbage value> are same
  • compilation error
  • runtime segmentation fault
Show Answer Report

22. *1* char st [ ] = &quot;Mandaveli&quot;; *2* char *p; *3* strcpy (p, st); *4* printf (&quot;%s and %s are same&quot;, st, p); If the code does result in error, what is the solution to be taken?

  • the code will work fine and print the intended output
  • remove the statement 3 and edit statement 2 such that char *p=st;
  • allocate dynamic memory for the pointer p in statment 2 as char *p=(ch*) malloc (strlen (st) + 1);
  • both b and c
Show Answer Report

23. What will strcmp return, if both the strings are equal ?

  • boolean True
  • 0
  • 2
  • 1
Show Answer Report

24. Whioch of the following function is used to check the presence of a substring?

  • strstr ( )
  • substr ( )
  • check string ( )
  • none of the above
Show Answer Report

25. What does atoi ( ) function do ?

  • convert a string into an integer
  • convert string into a float
  • convert integer to string
  • convert float to string
Show Answer Report

26. What does strlen ( ) return for the following character array ? char str [ ] = &quot;MIT\OIT&quot;;

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