Machine-translated by Google. Questions are authored in English.
Top

Strings Questions and Answers

Answer: B

Correct answer: places character c into first n characters of s, return s

Read the arguments in order: memset(s, c, n) fills the first n bytes of s with the byte c, and returns s. It is the usual way of zeroing a buffer, as memset(buf, 0, sizeof buf). Note that c is converted to unsigned char, so it sets bytes, not wider values.

Please log in or register to report this question.

Answer: C

Correct answer: manipulates sequence of non – null characters.

The strn functions take an explicit count and process at most that many characters, so they do not depend on a terminating null being present. That is what makes them the safer choice with a fixed-size buffer - though strncpy in particular does not add a null of its own if the source fills the whole n.

Please log in or register to report this question.

33.

Which of the following is the right syntax to copy n characters from the object pointed to by s2 into the object pointed to by s1?

Answer: A

Correct answer: void *memcpy(void *s1,const void *s2,size_t n);

The destination comes first, as it does throughout the library - the same order as an assignment. The source is const, since it is only read, and the function returns void *, the destination pointer, so calls can be chained. The two regions must not overlap; memmove is the version that copes if they do.

Please log in or register to report this question.

34.

What does the function void *memmove(void *s1, const void *s2, size_t n); return?

Answer: A

Correct answer: returns the value of s1

memmove returns its destination pointer, s1 - as memcpy, strcpy and strcat all do. Returning the destination lets a call be used directly as an argument to another function. Its distinctive property is that it works correctly even when the two regions overlap, which memcpy does not guarantee.

Please log in or register to report this question.

Answer: A

Correct answer: length of the transformed string, not including the terminating null-character

strxfrm transforms a string so that comparing two transformed strings with strcmp gives the same order as comparing the originals with strcoll. It returns the length of the transformed string, excluding the null - so a caller can size the buffer by calling it once with a length of 0.

Please log in or register to report this question.

36.

Is there any function declared as strstr()?

Answer: A

This function returns a pointer to the first occurrence in s1 of any of the entire sequence of characters specified in s2, or a null pointer if the sequence is not present in s1.
char *strstr(const char *s1, const char *s2)

Please log in or register to report this question.

37.

The C library function _________ breaks string s1 into a series of tokens using the delimiter s2.

Answer: A

Correct answer: char *strtok(char *s1,const char *s2);

strtok splits s1 into tokens separated by any of the characters in s2. The first call passes the string; every later call passes NULL to continue where it left off. Note that it modifies the string, writing a null over each delimiter, and keeps state between calls, which makes it unsuitable for reentrant or threaded code.

Please log in or register to report this question.

38.

The______function returns a pointer to the first character of a token.

Answer: D

Correct answer: strtok()

strtok() returns a pointer to the first character of the next token, or NULL when there are none left. It finds a token by skipping leading delimiters and then writing a null over the delimiter that ends it.

Please log in or register to report this question.

39.

Which of the following functions returns a pointer to the located string or a null pointer if string is not found.

Answer: B

Correct answer: strstr()

strstr(haystack, needle) searches for the first occurrence of one string inside another and returns a pointer to where it begins, or NULL if it is not there. strchr finds a single character rather than a string.

Please log in or register to report this question.

40.

Which of the given function is used to return a pointer to the located character?

Answer: D

Correct answer: strchr()

strchr() returns a pointer to the located character - the first occurrence of it in the string - or NULL. strrchr finds the last occurrence, memchr searches a fixed-length block rather than a string, and strxfrm transforms rather than searches.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Strings Questions and Answers || Strings MCQ Questions and Answers || Strings GK Questions and Answers || Strings GK MCQ Questions || Strings Multiple Choice Questions and Answers || Strings GK || GK on Strings || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming