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);
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
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?
*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";
char str [ ] = "MIT\OIT";
- 5
- 6
- 3
- 7