Strings - General Questions Multiple Questions and Answers.
Exercise Questions ::
Strings
Answer: Option B
Explanation:
Declaration :
char *strnset(char *s, int ch, size_t n); Sets the first n characters of s to ch
#include <stdio.h>
#include <string.h>
int main(void )
{
char *string = "abcdefghijklmnopqrstuvwxyz" ;
char letter = 'x' ;
printf("string before strnset: %s\n" , string );
strnset(string , letter, 13 );
printf("string after strnset: %s\n" , string );
return 0 ;
}
Output :
string before strnset: abcdefghijklmnopqrstuvwxyz
string after strnset: xxxxxxxxxxxxxnopqrstuvwxyz
See More Information
Tutorial Link:
Published by:Michael Daani
Answer: Option C
Explanation:
Declaration : strcmp(const char *s1, const char*s2);
The strcmp return an int value that is
if s1 < s2 returns a value < 0
if s1 == s2 returns 0
if s1 > s2 returns a value > 0
See More Information
Tutorial Link:
Published by:Michael Daani
Answer: Option D
Explanation:
The statement printf("\\n"); prints '\n' on the screen.
See More Information
Tutorial Link:
Published by:Michael Daani
Answer: Option C
Explanation:
Declaration : char *strrchr(const char *s, int c);
It scans a string s in the reverse direction, looking for a specific character c .
See More Information
Tutorial Link:
Published by:Michael Daani
5. Which of the following function is used to find the first occurrence of a given string in another string?
A. strchr() B. strrchr() C. strstr() D. strnset()
View Answer
Discuss forum
Workplace
Report
Answer: Option C
Explanation:
The function strstr() Finds the first occurrence of a substring in another string
Declaration : char *strstr(const char *s1, const char *s2);
Return Value : On success, strstr returns a pointer to the element in s1 where s2 begins (points to s2 in s1 ). On error (if s2 does not occur in s1 ), strstr returns null.
See More Information
Tutorial Link:
Published by:Michael Daani
»