C Strings Questions and Answers

Practice Mode
Showing 10 of 26 questions
Q21
What will be the output ? char st [ ] = "India"; char *p; strcpy (p, st); printf("%s and %s are same", st, p);
  • A India and India are same
  • B India and <some Garbage value> are same
  • C compilation error
  • D runtime segmentation fault
Answer: Option D
Q22
*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?
  • A the code will work fine and print the intended output
  • B remove the statement 3 and edit statement 2 such that char *p=st;
  • C allocate dynamic memory for the pointer p in statment 2 as char *p=(ch*) malloc (strlen (st) + 1);
  • D both b and c
Answer: Option D
Q23
What will strcmp return, if both the strings are equal ?
  • A boolean True
  • B 0
  • C 2
  • D 1
Answer: Option B
Q24
Whioch of the following function is used to check the presence of a substring?
  • A strstr ( )
  • B substr ( )
  • C check string ( )
  • D none of the above
Answer: Option A
Q25
What does atoi ( ) function do ?
  • A convert a string into an integer
  • B convert string into a float
  • C convert integer to string
  • D convert float to string
Answer: Option A
Q26
What does strlen ( ) return for the following character array ? char str [ ] = &quot;MIT\OIT&quot;;
  • A 5
  • B 6
  • C 3
  • D 7
Answer: Option C
Questions and Answers for Competitive Exams Various Entrance Test