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

11. char *a="23422"; sozeof (a), strlen(a)); From the above, what is the output of the printf function ?

  • 4 4
  • 5 5
  • 5 4
  • 4 5
Show Answer Report

12. char name [ ] = 'MIT' printf ("%s is deprtment %s %d of %s/n', &name [1], "no", ('A' 'a')/", name); From the above, what is the output of the printf statement ?

  • IT is department no 1 of MIT
  • L value required RUNTIME ERROR
  • IT is department no-1 of MIT
  • compilation error
Show Answer Report

13. char *p; char name [25] = "MIT-IT"; strcpy (p,name); printf("%s",p); What will be the output?

  • segmentation fault because pointer p is only declared but no memory allocated
  • compilation error
  • MIT-IT
  • none of the above
Show Answer Report

14. char name [10]; scanf ("%s", name); if (strcmp (name, "chennai") = = 0 { char a[10] = "600028"; printf ("Mandaveli has the pin code: %s\n",a); } What will be the amount of memory allocated in the following cases'? case 1 input is not chennai, case 2 input is chennai

  • in both cases, the total amount of memory allocated will be the same
  • the total amount of memory allocated difffers based on the input
  • based on the compiler options
  • both (a) and (c)
Show Answer Report

15. char *name = "Delhi"; printf ("%d %d", sizeo (name), sizeof ()*name)); What will be the output?

  • 4 1
  • 4 4
  • 5 1
  • 5 4
Show Answer Report

16. Which of the following is the correct output for the program given? main ( ) { char str [ ]="Sales \0man\0"; printf ("%d %s %d \n", sizeof (str), strlen (str)); }

  • 5 sales 5
  • 11 sales 9
  • 11 sales man 9
  • 11 sales 5
Show Answer Report

17. Which of the following is the correct output for the program given ? char str [7] = "strings"; printf ("%s", str);

  • error
  • strings
  • cannot predict
  • none of the above
Show Answer Report

18. If sizes of a char, an int, a float and a double are 1, 4, 4 and 8 bytes respectively, which of the following is the correct output for the program given below? { char ch = 'A'; printf ("%d%d%d", sizeof (ch), sizeof (sizeof('A')), sizeof (3 . 14)); }

  • 1 4 2
  • 1 4 8
  • 2 2 4
  • 2 4 8
Show Answer Report

19. What is the value of str3 and sdtr1; void main ( ) { char str1 [100] = "united"; char *str2="front"; char *str3; str3 = strcat (str1, str2) printf ("\n////5s", str3); }

  • compilation error because strcat does not return a value
  • united front
  • segmentation fault because str3 might be pointing to a ggarbage value
  • united
Show Answer Report

20. Consider the following declarations: char *a; char a[5]; Which of the following statements is/are true? 1. both are of pointer type 2. memory allocation is different in both the cases 3. the value of a in drclaration char a [5] can be changed later

  • (2) only
  • (1) only
  • (1) and (2)
  • (2) and (3)
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test