Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

fgetc, getc, getchar are all declared in ________(a) stdio. h(b) ctype. h(c) assert. h(d) stdarg. hI got this question in an interview.Origin of the question is Character Handling in chapter String Operations in C of C

Answer» RIGHT answer is (a) stdio. h

Explanation: The FUNCTIONS getc, fgetc, getchar are all declared in stdio.h HEADER FILE.
2.

Which function returns true only for the characters defined as lowercase letters?(a) islow()(b) islower()(c) isalpa()(d) isalnum()The question was asked in an internship interview.My doubt stems from Character Handling topic in division String Operations in C of C

Answer»

Right choice is (b) islower()

EASY EXPLANATION - INT islower( int C);

The islower function tests for any CHARACTER that is a lowercase letter.

3.

What is the function of strcoll()?(a) compares the string, result is dependent on the LC_COLLATE(b) copies the string, result is dependent on the LC_COLLATE(c) compares the string, result is not dependent on the LC_COLLATE(d) copies the string, result is not dependent on the LC_COLLATEI have been asked this question in an interview for job.My question is taken from String Operations in division String Operations in C of C

Answer» RIGHT choice is (a) compares the string, RESULT is DEPENDENT on the LC_COLLATE

Easiest explanation - The strcoll() FUNCTION compares the string s1 to the string s2, both interpreted as appropriate to the LC_COLLATE CATEGORY of the current locale.
4.

ERANGE is reported on an overflow or an underflow.(a) true(b) falseThe question was asked in a national level competition.This intriguing question originated from Error Handling in chapter String Operations in C of C

Answer»

The correct ANSWER is (a) true

Explanation: This macro REPRESENTS a range ERROR, which occurs if an INPUT argument is outside the range, over which the MATHEMATICAL function is defined and errno is set to ERANGE.

5.

What occurs when a result has nowhere near the number of significant digits indicated by its type.(a) domain(b) underflow(c) overflow(d) significance lossI got this question in a job interview.Question is taken from Error Handling in chapter String Operations in C of C

Answer» RIGHT answer is (d) significance loss

The explanation: A significance loss OCCURS when a result has NOWHERE near the number of significant DIGITS indicated by its type.
6.

The C library function checks whether the passed character is printable.(a) isgraph()(b) isalpha()(c) isprint()(d) ispunct()The question was posed to me in an interview.I'd like to ask this question from Character Handling topic in portion String Operations in C of C

Answer»

Right ANSWER is (c) isprint()

Easiest explanation - int isprint(int c) function is used to CHECK whether the passed CHARACTER can be printed.A CONTROL character is not a PRINTABLE character.

7.

The________function converts an uppercase letter to the corresponding lowercase letter.(a) islower()(b) isupper()(c) toupper()(d) tolower()The question was asked by my school teacher while I was bunking the class.I want to ask this question from Character Handling topic in chapter String Operations in C of C

Answer»

Right choice is (d) tolower()

Best EXPLANATION: If the argument is a character for which isupper() is true andislower() is true for ANOTHER set of character, the tolower() FUNCTION returns the corresponding character;otherwise, the argument is returned UNCHANGED.

8.

The______function returns a pointer to the first character of a token.(a) strstr()(b) strcpy()(c) strspn()(d) strtok()The question was asked during an internship interview.My question is taken from String Operations in section String Operations in C of C

Answer» CORRECT ANSWER is (d) strtok()

The EXPLANATION: The strtok() function returns a pointer to the first character of a TOKEN, if there is no token then a null pointer is returned.
9.

Which function will you choose to join two words?(a) strcpy()(b) strcat()(c) strncon()(d) memcon()The question was posed to me in an interview for internship.My enquiry is from String Operations topic in section String Operations in C of C

Answer»

The CORRECT CHOICE is (b) strcat()

Explanation: The strcat() function is used for concatenating two STRINGS, APPENDS a copy of the string.

char *strcat(char *S1,const char *s2);

10.

The mem functions are meant for _______(a) returning a pointer to the token(b) manipulating objects as character arrays(c) returning a pointer for implemented-defined string(d) returning a pointer to first occurrence of string in another stringI got this question in exam.This key question is from String Operations topic in division String Operations in C of C

Answer»

The correct OPTION is (b) manipulating OBJECTS as CHARACTER ARRAYS

Best explanation: The mem FUNCTIONS is used for manipulating objects as character arrays.

11.

Which code from the given option return pointer to last occurrence of c in ch or NULL if not present?(a) char *strchr(ch, c)(b) char *strrchr(ch, c)(c) char *strncat(ch, c)(d) char *strcat(ch, c)The question was posed to me in homework.Query is from String Operations topic in division String Operations in C of C

Answer»

Right option is (b) CHAR *strrchr(ch, c)

For EXPLANATION: The FUNCTION char *strrchr(ch, c)returns pointer to last OCCURRENCE of c in ch or NULL if not present.

12.

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?(a) void *memcpy(void *s1,const void *s2,size_t n);(b) void *memcpy(void*s2, const void *s1, size_t n);(c) void memcpy(void*s1,const void *s2, size_t n);(d) void memcpy(void *s2,const void *s1,size_t n);This question was posed to me during an interview.Query is from String Operations topic in section String Operations in C of C

Answer»

The correct ANSWER is (a) void *memcpy(void *s1,const void *s2,size_t N);

The explanation: The memcpy() function COPIES n CHARACTERS from the object pointed to by s2 into the object pointed to by s1. If copying takes place between objects that overlap, the behavior is undefined.

13.

This function offers the quickest way to determine whether two character sequences of the same known length match character for the character up to and including any null character in both.(a) strcmp()(b) memcmp()(c) strncmp()(d) no such functionThis question was addressed to me during an internship interview.The origin of the question is String Operations topic in division String Operations in C of C

Answer»

Correct answer is (c) strncmp()

For EXPLANATION: The strncmp() function is used to compare not more than n CHARACTERS (characters that follow a NULL character are not COMPARED) from the array pointed to by ONE, to the array pointed to by other.

14.

The C library function _________ breaks string s1 into a series of tokens using the delimiter s2.(a) char *strtok(char *s1,const char *s2);(b) char*strtok(char *s2,const char *s1);(c) char *strstr(char *s1,const char *s2);(d) char *strstr(char *s2,const char *s1);The question was asked in a national level competition.I would like to ask this question from String Operations in section String Operations in C of C

Answer» CORRECT choice is (a) char *strtok(char *s1,const char *s2);

EXPLANATION: The C LIBRARY function char *strtok(char *s1, const char *s2) breaks string s1 into a SERIES of tokens using the delimiter s2.
15.

What is the use of function char *strchr(ch, c)?(a) return pointer to first occurrence of ch in c or NULL if not present(b) return pointer to first occurrence of c in ch or NULL if not present(c) return pointer to first occurrence of ch in c or ignores if not present(d) return pointer to first occurrence of cin ch or ignores if not presentThis question was addressed to me by my college professor while I was bunking the class.This key question is from String Operations topic in division String Operations in C of C

Answer»

The CORRECT option is (b) RETURN pointer to first occurrence of c in ch or NULL if not PRESENT

The BEST explanation: The given code char *strchr(ch, c)return pointer to first occurrence of c in ch or NULL if not present.

16.

Which among the following is Copying function?(a) memcpy()(b) strcopy()(c) memcopy()(d) strxcpy()The question was posed to me in an interview.The question is from String Operations topic in section String Operations in C of C

Answer»

The CORRECT CHOICE is (a) memcpy()

The explanation is: The memcpy() function is used tocopy N characters from the object.

The code is void *memcpy(void *s1,CONST void *s2, size_t n).

17.

The ______ function appends not more than n characters.(a) strcat()(b) strcon()(c) strncat()(d) memcat()I have been asked this question in semester exam.Query is from String Operations topic in division String Operations in C of C

Answer»

The CORRECT choice is (C) strncat()

The EXPLANATION is: The strncat() function appends not more than n characters from the ARRAY(s2) to the END of the string(s1).char *strncat(char *s1, const char *s2,size_t n);

18.

What is the function of void *memset(s, c, n)?(a) places character s into first n characters of c, return c(b) places character c into first n characters of s, return s(c) places character s into first n characters of c, return s(d) places character c into first n character of s, return cThis question was posed to me in homework.I'm obligated to ask this question of String Operations topic in chapter String Operations in C of C

Answer»

Correct answer is (b) PLACES character c into first N CHARACTERS of s, return s

Easiest EXPLANATION - The void *memset(s, c, n)places character c into first n characters of s, return s.

19.

What will strcmp() function do?(a) compares the first n characters of the object(b) compares the string(c) undefined function(d) copies the stringThis question was addressed to me by my school teacher while I was bunking the class.I need to ask this question from String Operations topic in portion String Operations in C of C

Answer»

Right ANSWER is (b) compares the STRING

Easiest EXPLANATION - The strcmp() function compares the string s1 to the string S2.

int strcmp(CONST char *s1,const char *s2);

20.

The______function tests for any character for which isalpha or isdigit is true.(a) isxdigit()(b) isspace()(c) isalnum()(d) isupper()The question was posed to me in class test.Query is from Character Handling topic in portion String Operations in C of C

Answer»

The correct option is (C) isalnum()

EXPLANATION: int isalnum(int c)

The isalnum FUNCTION TESTS for any character for which isalpha or isdigit is TRUE.

21.

Which among the given options compares atmost n characters of string ch to string s?(a) int strncmp(ch, s, n)(b) int strcmp(ch, s)(c) int strncmp(s, ch, n)(d) int strcmp(s, ch)The question was posed to me in unit test.This interesting question is from String Operations topic in section String Operations in C of C

Answer»

Correct choice is (a) int strncmp(CH, s, n)

Explanation: int strncmp(ch, s, n)is USED to COMPARE at most n CHARACTERS of string ch to string s; return <0 if ch0 of ch >s.

22.

errno causes trouble in two subtler ways(vague and explicit).(a) true(b) falseThis question was addressed to me during an interview.This intriguing question originated from Error Handling in section String Operations in C of C

Answer»

Right answer is (a) true

To explain I WOULD SAY: errno causes trouble in TWO subtler ways – sometimes its specification is too VAGUE and sometimes it is too explicit.

23.

______ is reported on a domain error.(a) EDOM(b) ERANGE(c) Significance loss(d) UnderflowI have been asked this question during an interview.I would like to ask this question from Error Handling topic in portion String Operations in C of C

Answer»

The CORRECT ANSWER is (a) EDOM

The best I can explain: EDOM is reported on a domain ERROR.

24.

isalpha() function is used to detect characters both in uppercase and lowercase.(a) true(b) falseI had been asked this question in an online interview.This question is from Character Handling in chapter String Operations in C of C

Answer» CORRECT option is (a) true

Explanation: ISALPHA() function is used to test for letters in the local alphabet. For the locale, the local alphabet CONSISTS of26 ENGLISH letters, in each of two CASES.
25.

The toupper() function converts a ______ to the corresponding ______(a) uppercase, lowercase(b) lowercase, uppercase(c) binary, decimal(d) decimal, binaryI had been asked this question in unit test.This is a very interesting question from Character Handling in portion String Operations in C of C

Answer»

Correct choice is (b) lowercase, UPPERCASE

The explanation: The toupper() FUNCTION is used to convert a lowercase LETTER to the corresponding uppercase letter.

If the value is a character for which islower() is true and isupper () is true for another set of CHARACTERS, the toupper() function returns the corresponding character, otherwise, the value is RETURNED unchanged.

26.

The strpbrk() function is used to return a pointer to the character, or a null pointer if no character from s2 occurs in s1.(a) true(b) falseI had been asked this question in examination.The doubt is from String Operations in portion String Operations in C of C

Answer»

The CORRECT option is (a) true

For EXPLANATION: CHAR *strpbrk(const char *S1,const char *S2);

The first occurrence in the string s1 of any character from the string s2 is done by strpbrk().

27.

Which function tests for any character that is an uppercase letter.(a) iscntrl()(b) ispunct()(c) isdigit()(d) isupper()This question was addressed to me in semester exam.Question is from Character Handling topic in division String Operations in C of C

Answer»

Correct choice is (d) isupper()

Explanation: isupper() returns TRUE only for the CHARACTERS defined as UPPERCASE LETTERS.

28.

Is there any function declared as strstr()?(a) true(b) falseI had been asked this question in an interview.Asked question is from String Operations topic in portion String Operations in C of C

Answer»

Correct answer is (a) true

The best I can EXPLAIN: 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)

29.

No library function will store a zero in errno.(a) true(b) falseThis question was posed to me in an interview.My question is based upon Error Handling topic in division String Operations in C of C

Answer»

Correct answer is (a) true

The explanation is: Any LIBRARY function can STORE NONZERO VALUES in errno.

30.

This function checks whether the passed character is white-space.(a) ispunct()(b) isgraph()(c) isspace()(d) isalpha()The question was asked during a job interview.This intriguing question originated from Character Handling topic in section String Operations in C of C

Answer»

The CORRECT CHOICE is (c) isspace()

For explanation: The isspace FUNCTION tests for any character that is a STANDARD white-space character.

31.

Which of the given function is used to return a pointer to the located character?(a) strrchr()(b) strxfrm()(c) memchar()(d) strchar()I had been asked this question by my school principal while I was bunking the class.I need to ask this question from String Operations in division String Operations in C of C

Answer»

Correct ANSWER is (d) strchar()

The BEST explanation: The strchr() FUNCTION is used to return a pointer to the LOCATED CHARACTER if character does not occur then a null pointer is returned.

32.

What is the prototype of strcoll() function?(a) int strcoll(const char *s1,const char *s2)(b) int strcoll(const char *s1)(c) int strcoll(const *s1,const *s2)(d) int strcoll(const *s1)This question was addressed to me during an interview.I'd like to ask this question from String Operations in chapter String Operations in C of C

Answer»

The CORRECT OPTION is (a) int strcoll(const char *S1,const char *s2)

The EXPLANATION is: The PROTOTYPE of strcoll() function is int strcoll(const char *s1,const char *s2).

33.

Which among the given options is the right explanation for the statement size_t strcspn(c, s)?(a) return length of prefix of s consisting of characters not in c(b) return length of prefix of s consisting of characters present in c(c) return length of prefix of c consisting of characters not in s(d) return length of prefix of c consisting of characters present in sThis question was posed to me in quiz.This interesting question is from String Operations topic in section String Operations in C of C

Answer»

Correct CHOICE is (c) return length of PREFIX of c consisting of characters not in s

To EXPLAIN: The function size_t strcspn(c, s)is used to return length of prefix of c consisting of characters not in s.

34.

There are two groups of string functions defined in the header . What are they?(a) first group names beginning with str; second group names beginningwith mem(b) first group names beginning with str; second group names beginning with is(c) first group names beginning with string; second group names beginning with mem(d) first group names beginning with str; second group names beginning with typeThe question was asked in a national level competition.This interesting question is from String Operations in portion String Operations in C of C

Answer»

The CORRECT choice is (a) FIRST group names beginning with str; SECOND group names beginningwith mem

The best explanation: There are two GROUPS of string FUNCTIONS declared under the header . The first have names beginning with str and second have names beginning with mem.

35.

What error occurs when a result is undefined for a given argument value?(a) significance loss(b) underflow(c) overflow(d) domainThe question was asked during an interview.My question comes from Error Handling topic in chapter String Operations in C of C

Answer»

Correct answer is (d) domain

The BEST I can explain: A domain error OCCURS when a RESULT is undefined for a given ARGUMENT VALUE.

36.

The isdigit function tests for any decimal-digit character.(a) true(b) falseThe question was asked during an interview.I would like to ask this question from Character Handling in portion String Operations in C of C

Answer»

Correct answer is (a) true

The best explanation: int isdigit(int C);

This FUNCTION CHECKS whether the passed character is a DECIMAL digit.

37.

Functions whose names begin with “strn”(a) manipulates sequences of arbitrary characters(b) manipulates null-terminated sequences of characters(c) manipulates sequence of non – null characters.(d) returns a pointer to the tokenThis question was addressed to me in an interview.The origin of the question is String Operations topic in division String Operations in C of C

Answer»

Right OPTION is (c) manipulates sequence of non – NULL characters.

The BEST I can explain: Functions WHOSE names begin with “strn”manipulates the sequence of non-null characters.

38.

What is the return value of strxfrm()?(a) length of the transformed string, not including the terminating null-character(b) length of the transformed string, including the terminating null-character(c) display the transformed string, not including the terminating null character(d) display the transformed string, not including the terminating null-characterThis question was addressed to me in a job interview.The above asked question is from String Operations topic in division String Operations in C of C

Answer»

Correct option is (a) length of the transformed string, not INCLUDING the TERMINATING null-character

The EXPLANATION: This function RETURNS the length of the transformed string, not including the terminating null character.

39.

Use_______to determine the null-terminated message string that corresponds to the error code errcode.(a) strerror()(b) strstr()(c) strxfrm()(d) memset()I have been asked this question at a job interview.I'm obligated to ask this question of String Operations topic in chapter String Operations in C of C

Answer»

Correct CHOICE is (a) strerror()

The best I can explain: Use strerror (errcode) to determine the null-terminated message STRING that corresponds to the ERROR code errcode.

40.

The function strsp() is the complement of strcspn().(a) true(b) falseI got this question in homework.This interesting question is from String Operations topic in section String Operations in C of C

Answer»

The correct option is (a) true

Best EXPLANATION: Both strcspn() and strpbrk() perform the same function. Only STRSPN() the RETURN values DIFFER. The function strspn() is the complement of strcspn() .

41.

which of the following function returns a pointer to the located string or a null pointer if string is not found.(a) strtok()(b) strstr()(c) strspn()(d) strrchr()I got this question in my homework.This intriguing question originated from String Operations in division String Operations in C of C

Answer»

Right option is (b) strstr()

Easy explanation - The strstr() FUNCTION is used to RETURN a POINTER to the located string, or if string is not FOUND a NULL pointer is returned.

42.

Which of the following is the variable type defined in header string. h?(a) sizet(b) size(c) size_t(d) size-tThis question was addressed to me during an online exam.My question is taken from String Operations in division String Operations in C of C

Answer»

Right ANSWER is (c) size_t

The EXPLANATION: This is the unsigned INTEGRAL type and is the result of the SIZEOF keyword.

43.

_______ occurs when a result is too large in magnitude to represent errors as a floating-point value of the required type.(a) underflow(b) significance loss(c) domain(d) overflowThis question was posed to me during an interview.Question is from Error Handling topic in division String Operations in C of C

Answer»

The CORRECT answer is (d) overflow

The BEST I can EXPLAIN: An overflow occurs when a RESULT is too large in magnitude to REPRESENT errors as a floating-point value of the required type.

44.

Which header declares several functions useful for testing and mapping characters?(a) assert.h(b) stdio.h(c) ctype.h(d) errno.hThis question was posed to me by my college director while I was bunking the class.Enquiry is from Character Handling topic in portion String Operations in C of C

Answer» CORRECT ANSWER is (c) ctype.h

Easiest explanation - The HEADER declares several functions useful for testing and MAPPING characters.