C-Strings Question and Answer

C-Strings Question and Answer
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 are same
  • compilation error
  • runtime segmentation fault
Show Answer
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
Show Answer
23. What will strcmp return, if both the strings are equal ?
  • boolean True
  • 0
  • 2
  • 1
Show Answer
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
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
26. What does strlen ( ) return for the following character array ?
char str [ ] = "MIT\OIT";
  • 5
  • 6
  • 3
  • 7
Show Answer
Questions and Answers for Competitive Exams Various Entrance Test