C Strings Questions and Answers
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
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
22. *1* char st [ ] = "Mandaveli"; *2* char *p; *3* strcpy (p, st); *4* printf ("%s and %s are same", 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
24. Whioch of the following function is used to check the presence of a substring?
- strstr ( )
- substr ( )
- check string ( )
- none of the above
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
26. What does strlen ( ) return for the following character array ? char str [ ] = "MIT\OIT";
- 5
- 6
- 3
- 7